Common misconception : Files have an EOF char at their end

纵然是瞬间 提交于 2019-12-21 05:56:10

问题


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 ?


回答1:


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




回答2:


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.




回答3:


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




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/9907416/common-misconception-files-have-an-eof-char-at-their-end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!