Rsh
Rsh

Reputation: 7752

Common misconception : Files have an EOF char at their end

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 ?

Upvotes: 4

Views: 5934

Answers (5)

sietschie
sietschie

Reputation: 7553

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.

Upvotes: 6

John Bode
John Bode

Reputation: 123578

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.

Upvotes: 0

asaelr
asaelr

Reputation: 5456

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).

Upvotes: 4

P.P
P.P

Reputation: 121427

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.

Upvotes: 0

Peter Miehle
Peter Miehle

Reputation: 6080

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

Upvotes: 7

Related Questions