It depends on how the file is opened when reading. If opened as text, everything after the EOF character will be unreadable. If opened as binary, nothing special will happen. |
That's misleading - it totally depends on the software reading the written file, and if the software's written correctly, using the eof()/feof() functions, it will read straight past the EOF character, stopping at the REAL end-of-file.
For example, use the following code to generate a text file with an EOF character in the middle.
1 2 3 4 5 6 7 8 9
|
FILE* fptr;
if (fopen_s(&fptr, "c:\\EOFs.txt", "w") == 0)
{
fputs("This is a file", fptr);
fputc(EOF, fptr);
fputs("This is after the EOF", fptr);
fclose(fptr);
}
|
Open the text file (I used notepad++) and you'll see the following content.
This is a fileÿThis is after the EOF |
Depending on the O/S, the physical DISK may have an end-of-file marker byte, but it's NOT part of the actual file content, and WILL NOT SHOW UP as a read character by software reading the file content.
For binary files (or the example file created by the code above), your fgetc() call may return -1/EOF. If it does, you should then check feof() to see whether it's a byte value read from the file, or whether you really have reached the end of data.
For the file above, you'll get two instances of -1 being returned - the first for the EOF byte that's actually in the file, which when you call feof() on it will return FALSE, and the second for the actual EOF condition, at which point feof() will return TRUE.
Cheers,
Jim