Answer: there aren't any characters beyond the end of a file. My MSVC manual page here says that if you read past the end of the file, getc()
returns EOF
.
It does not matter how many times you try to make getc()
read past the end of the file, it won't. It just keeps returning EOF
.
The EOF
is not part of the file marking its end - it is a flag value returned by getc()
to tell you there is no more data.
EDIT included a sample to show the behaviour of feof()
. Note, I made separate printf()
statements, rather than merging them into a single statement, because it is important to be clear what order the functions feof()
and getc()
are called.
Note that feof()
does not return a non-0 value until after getc()
returned EOF
.
#include <stdio.h>
int main( void )
{
FILE *fr;
int i;
fr=fopen("file.txt","r");
for (i=0;i<6;i++) {
printf("feof=%04X, ", feof(fr));
printf("getc=%04X\n", getc(fr));
}
fclose(fr);
}
Program input file:
abc\n
Program output:
feof=0000, getc=0061
feof=0000, getc=0062
feof=0000, getc=0063
feof=0000, getc=000A
feof=0000, getc=FFFFFFFF
feof=0010, getc=FFFFFFFF
So, you can't use feof()
to tell you the end of file was reached. It tells that you made a read error after reaching the end of file.