This is a "BUGBUSTER" from the book "teach yourself C in 21 days". The question is: Is there anything worng with this code. My opinion: NO. But the book says this:Code:FILE *fp; int c; if ((fp = fopen (oldname, "rb")) == NULL) return -1; while ((c = fgetc(fp)) != EOF) fprintf(stdout, "%c", c); fclose(fp);
"You can't use the EOF check with a binary file. You should use the feof() function". As i read on the forum here, you must not use feof at all!!.
But when i look in the K&R "bible" it says this:
"fgetc returns the next charakter of stream as an unsigned char (converted to an int), or EOF if end of file or error occurs"
It says it return EOF when the file ends, so the above code is ok i think.
Can some experts give their opinion ?