#include <stdio.h>
int main(int argc, char **argv) {
FILE *file = fopen(argv[1], "r");
char buf[100];
while (fgets(buf, sizeof(buf), file)) {
fprintf(stderr, "%s: unparseable line: '%s', ignored\n", argv[0], buf);
}
}
I got this random bug in my code. Consider this file
echo 1
echo 2
echo 3
If I were to do
$ gcc -Wall above.c
$ ./a.out file
./a.out: unparseable line: 'echo 1
', ignored
./a.out: unparseable line: 'echo 2
', ignored
./a.out: unparseable line: 'echo 3
', ignored
Why is the "', ignored" in it's own line? I want it to be 3 lines only not 6. Anyway to fix?