Well, EOF
is just a value returned by the function defined in the C stdio.h
header file. Its actually returned to all the reading functions by the OS, so its system dependent. When OS reaches the end of file, it sends it to the function, which in its return value than places most commonly (-1
), but not always. So, to summarize, EOF
is not character, but constant returned by the OS.
EDIT: Well, you need to know more about filesystem, look at this.
Hi, to your second question:
once again, you should look better into filesystems
. FAT is very nice example, becouse you can find many articles about it, and its principles are very similiar to NTFS. Anyway, once again, EOF is NOT a character
. You cannot place it in file directly. If you could do so, imagine the consequences, even "dumb" image file could not be read by the system.
Why? Becouse OS works like very complex structure of layers. One of the layer is the filesystem driver. It makes sure that it transfers data from every filesystem known to the driver. It provides bridge between applications and the actuall system of storing files into HDD.
To be exact, FAT filesystem uses so-called FAT table - it is a table located close to the start of the HDD (or partition) adress space, and it contains map of all clusters (little storage cells). OK, so now, when you want to save some file to the HDD, OS (filesystem driver) looks into FAT table, and searches for the value "0x0". This "0x0" value says to the OS that cluster which adress is described by the location of that value in FAT table is free to write.
So it writes into it the first part of the file. Than, it looks for another "0x0" value in FAT, and if found, it writes second part of the file into cluster which it points to. Than, it changes the value of the first FAT table record where the file is located to the physical adress of the next in our case second part of the file.
When your file is all stored on HDD, now there comes the final part, it writes desired EOF value, but into FAT table, not into the "data part" of the HDD. So when the file is read next time, it knows this is the end, don´t look any further.
So, now you see, if you would want to manually write EOF value into the place it doesen´t belong to, you have to write your own driver which would be able to rewrite the FAT record, but this is practically impossible to do for begginers.