Looping while feof
returns zero is almost never correct.
Instead you might want to read from the input and check that the input function didn't fail in one expression:
int ch;
while ((ch = getc(fp)) != EOF)
putc(ch, stdout);
This reads a character using getc
, checks that the reading was successful by comparing the character against EOF
, and if it's not EOF
then continue the loop.
Besides, there's no use in calling rewind
immediately after opening the file, the file is already "rewound".