EOF用于二进制文件 [英] EOF for binary files

查看:280
本文介绍了EOF用于二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已读过一本书:


< quote>

使用二进制模式流,你无法检测到通过查看EOF的
结束文件,因为来自二进制流的一个字节数据可能具有

值,这将导致输入过早结束。相反,你可以使用库函数feof(),它可以用于二进制和

文本模式文件:


int feof(FILE * fp);

< / quote>


对于EOF的测试是否有效是不是真的文本和

二进制模式文件?


另外,FAQ建议不要使用feof():

< ;引用>几乎在所有情况下,都没有必要使用feof。

< / quote>

I''ve read in a book:

<quote>
With a binary-mode stream, you can''t detect the end-of-file by looking
for EOF, because a byte of data from a binary stream could have that
value, which would result in premature end of input. Instead, you can
use the library function feof(), which can be used for both binary- and
text-mode files:

int feof(FILE *fp);
</quote>

Isn''t it true that testing for EOF is valid for both text- and
binary-mode files?

Also, the FAQ recommends not to use feof():
<quote>In virtually all cases, there''s no need to use feof at all.
</quote>

推荐答案

注册用户说:
Registered User said:

我已读过一本书:


< ;引用>

使用二进制模式流,你不能通过查看EOF的
来检测文件结尾,因为来自a的一个字节的数据二进制流可能具有

值,这将导致输入过早结束。
I''ve read in a book:

<quote>
With a binary-mode stream, you can''t detect the end-of-file by looking
for EOF, because a byte of data from a binary stream could have that
value, which would result in premature end of input.



抛弃这本书。它不会理解EOF。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。

Ditch the book. It doesn''t understand EOF.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


Richard Heathfield写道:
Richard Heathfield wrote:

注册用户说:
Registered User said:

我已读过一本书:


< quote>

使用二进制模式流,你无法通过查看EOF的
来检测文件结尾,因为来自二进制流的一个字节数据可能具有/>
值,这将导致输入过早结束。
I''ve read in a book:

<quote>
With a binary-mode stream, you can''t detect the end-of-file by looking
for EOF, because a byte of data from a binary stream could have that
value, which would result in premature end of input.



抛弃这本书。它不明白EOF。


Ditch the book. It doesn''t understand EOF.



哦,谢谢Richard!这部分内容让我感到困惑。

Oh, thanks Richard!! That part of the book really got me confused.


注册用户说:
Registered User said:

Richard Heathfield写道:
Richard Heathfield wrote:

>注册用户说:
>Registered User said:

我在书中读过:


< quote>

使用二进制模式流,您无法通过查看
$来检测文件结尾对于EOF,b $ b,因为来自二进制流的一个字节数据可能具有

值,这将导致输入过早结束。
I''ve read in a book:

<quote>
With a binary-mode stream, you can''t detect the end-of-file by looking
for EOF, because a byte of data from a binary stream could have that
value, which would result in premature end of input.


放弃这本书。它不明白EOF。


Ditch the book. It doesn''t understand EOF.



哦,谢谢Richard!这本书的那一部分让我很困惑。

Oh, thanks Richard!! That part of the book really got me confused.



作者犯的错误是他似乎相信EOF是一个

字符。不是。这是来自你的I / O库的消息,它可以自由地翻译成b $ b,意思是你问我更多的数据,乡绅,但是那里没有

没有。锅是空的。抱歉,我很乐意帮助所有......


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。

The mistake the author makes is that he appears to believe EOF is a
character. It isn''t. It''s a message from your I/O library which, freely
translated, means "you asked me for more data, squire, but there ain''t
none. The pot''s empty. Sorry, I''d love to help and all that...".

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


这篇关于EOF用于二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆