I got the following programme from an old post:
http://tinyurl.com/53oa6o
It was given at a job interview and the question was
"The following program works, but what is a
potential problem with it? "
#include <stdio.h>
#include <stdlib.h>
int main() {
char buf[128];
FILE *fp = fopen(__FILE__, "r");
if (!fp) return EXIT_FAILURE;
while(!feof(fp)) {
if (fgets(buf, sizeof buf, fp))
puts(buf);
}
fclose(fp);
return 0;
}
My opinion follows below but you might want
to think about it before scrolling down.
The only problem I see with it is that it
might insert some extra newlines relative
to the original file. If the output of the
programme is meant to be recompiled
this might create problems. Otherwise
it seems fine to me.
Am I missing something ?