Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- int main (int argc, char* argv[]) {
- char buf[1024];
- int i, ln;
- char* c, *lineEnd;
- for (i = 1; i < argc; ++i) {
- FILE* fp = fopen (argv[i], "r");
- if (!fp) {
- printf ("%s: %s\n", argv[i], strerror (errno));
- continue;
- }
- for (ln = 1; fgets (buf, sizeof buf, fp); ++ln) {
- lineEnd = &buf[strlen (buf)]; // position of '\0'
- for (c = &buf[0]; *c == '\t'; ++c)
- ;
- if (c != &buf[0] && (*c == '\n' || *c == '\r'))
- printf ("%s:%d: line all tabs\n", argv[i], ln);
- else {
- // lineEnd - 2 to skip '\0' and '\n'
- if (lineEnd != &buf[0] && *(lineEnd - 2) == '\t')
- printf ("%s:%d: trailing tabs\n", argv[i], ln);
- }
- }
- fclose (fp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement