Just in case: if by "EOF" you mean the End-of-file character, this is just quite a stupid historical character with is still preserved but almost never used, because there are no reasons for using it. Please see:
http://en.wikipedia.org/wiki/End-of-file[
^].
The ways to read the file to the end totally depend on the structure you need to read. If the structure is well developed, and if you have to read all the available instances of such structure, you always know either the number of those instances, or you can calculate them from the total size of the file, or you can read complex variable-size structures sequentially, but know the exact size of the last chunk of data from the data you already have.
But suppose you have more sloppy situation, when you cannot predict if you are trying to read behind the actual end of file or not. In this case, you can figure out it from the result returned from
fread
:
http://www.cplusplus.com/reference/cstdio/fread/[
^].
(Don't get confused by this C++ documentation: it's also applicable to C.)
As you can see, it returns the total number of elements successfully read. If this number differs from the count parameter, either a reading error occurred or the end-of-file was reached while reading.
That's it.
—SA