I was reading "PC assembly language by Carter" and I saw this phrase in footnote of page 32 which made me so confused !
If we assume that files may have not EOF at their end (as the book says) is a correct statement, then how can we figure out where is end of a file ?
and it also arises another question : does fseek use EOF to go back and forth in file ?

- 7,214
- 5
- 36
- 45
-
5All files have a size. If you read from the first byte until the last (as indicated by the file size) you have reached the end of the file. No special _character_ marks the end of the file (think about trying to read binary data, how would the end-of-file byte differ from any other byte?). – Some programmer dude Mar 28 '12 at 12:27
-
The confusion might be that EOF by itself is simply short for "End Of File", and as such it can mean lots of things: the ASCII character 0x1A, the condition where an open file reader had reached the end, the function `eof()` or its result, the non-character constant `EOF` etc. – Mr Lister Mar 28 '12 at 12:34
-
@JoachimPileborg Just for fun, you should create a text file with a \x1A in the middle and then `type` it from the command line. – Mr Lister Mar 28 '12 at 12:40
-
@MrLister I know, in Windows reading from text files checks for `CTRL-Z` (i.e. the byte `0x1a`) as a special end-of-file character. Doesn't make it a _real_ end of file. – Some programmer dude Mar 28 '12 at 13:10
-
@JoachimPileborg No, but I'm afraid that's where much of the confusion comes from. You _can_ have an EOF character which is stored in a file and which flags an EOF, even if its ASCII name isn't "EOF"! – Mr Lister Mar 28 '12 at 13:17
-
The 0x1A byte is a terrible, painful [source of agony](http://stackoverflow.com/questions/12483711/serialdata-eof-circumstances). – Jonathon Reinhart Mar 21 '13 at 04:58
5 Answers
PC => ^Z : EOF
in the olde PC-days the ctrl-Z was the signal in a file for EOF.
under UNIX and other modern systems: after reading behind the stat.st_size, EOF is signalled

- 5,984
- 2
- 38
- 55
From http://www.drpaulcarter.com/cs/common-c-errors.php:
What is this value? EOF A common misconception of students is that files have a special EOF character at the end. There is no special character stored at the end of a file. EOF is an integer error code returned by a function.

- 4,213
- 2
- 17
- 28

- 7,425
- 3
- 33
- 54
Well, EOF
is not stored at the end of the file, and is not char
. EOF
is an error message, that read functions return when there is not more data to read. This is the reason that getchar
returns int
- it may return a char
converted to int
, or the int
EOF
(which is not valid char
, so if you got it, you can be sure that you passed the end of file).

- 5,438
- 1
- 16
- 22
EOF is not stored in the file. EOF (usually defined as -1) is returned by OS when there's no more data to read or an input error occurred. So once you reach the end of file, you must hit EOF.
My guess about the statement in your book is it meant "EOF is not necessarily be at the end of file but also possible to have it somewhere in the middle of a file".
This is true on expected input error.

- 117,907
- 20
- 175
- 238
In the context of C code, EOF
is simply an indication that there is no more data available for a given input stream. Whether that corresponds to a special EOF character in the file itself is a function of the underlying file or I/O system.

- 119,563
- 19
- 122
- 198