读取二进制文件查找EOF [英] Reading binary file finding EOF

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

问题描述

如何找到包含0xFF的文件的真实EOF。当我使用

fgetc并且它遇到0xFF时它会认为它是文件的结尾但它确实不是.b $ b真的不是。

How can I find the true EOF for a file that contains 0xFF. When I use
fgetc and it encounters 0xFF it thinks it''s the end of file but it
really isn''t.

推荐答案

sp ********* @ hotmail.com 写道:
如何找到包含0xFF的文件的真实EOF。当我使用
fgetc并遇到0xFF时,它认为它是文件的结尾但它确实不是。
How can I find the true EOF for a file that contains 0xFF. When I use
fgetc and it encounters 0xFF it thinks it''s the end of file but it
really isn''t.




EOF没有特征,这是一个条件。混淆可能来自一些非常旧的DOS版本,其中^ Z是文件标记的结尾。

但是0x00和0xFF之间的所有内容都完全正常且有效

可以由fgetc()返回的字符。这就是为什么fgets()的返回值是b,而不是char:因为所有可能的字符都是

有效返回值不在此范围内的值,定义为EOF(不要
甚至推测它的价值,而它通常是-1,不是必须的b $ b和1725也会这样做)当检测到

文件结束时返回。所以总是将你从fgetc()中获得的东西存储在一个int

(和_not_一个字符)中并将其与EOF进行比较。


问候,Jens

-

\ Jens Thoms Toerring ___ Je *********** @ physik.fu-berlin.de

\ __________________________ http://www.toerring.de


我将变量从char更改为int有用。谢谢Jens。

I changed the variable from char to int and now it works. Thanks Jens.


< Je *********** @ physik.fu-berlin.de>在消息中写道

news:32 ************* @ uni-berlin.de ...
<Je***********@physik.fu-berlin.de> wrote in message
news:32*************@uni-berlin.de...
sp ********* @ hotmail.com 写道:
定义为EOF(不要<甚至推测它的价值,而它通常是-1,这不是必要的,1725也会这样做。
sp*********@hotmail.com wrote:
defined as EOF (don''t
even speculate about it''s value, while it''s often -1 that''s not
necessary and 1725 would also do)




不,不会。 EOF必须是否定的。


来自ISO / IEC 9899:1999(E)7.19.1 / 3:

--------- -------------------------------------------------- ---

EOF


扩展为整数常量表达式,类型为int

和负值,即由几个函数返回

表示文件结束,也就是说,没有来自流的输入

------------- -------------------------------------------------

无论如何,对于字节大小可以容纳它的实现,值1725可以很容易地成为有效字符值

。另外,

如果基本执行字符集的成员存储在

a char对象中,则其值保证为正。

( 6.2.5 / 3)。


-Mike



No it would not. EOF must be negative.

From ISO/IEC 9899:1999 (E) 7.19.1/3 :
--------------------------------------------------------------
EOF

which expands to an integer constant expression, with type int
and a negative value, that is returned by several functions to
indicate end-of-file, that is, no more input from a stream
--------------------------------------------------------------
Anyway, the value 1725 could easily be valid character value
for implementations whose byte size can accomodate it. Also,
if a member of the basic execution character set is stored in
a char object, its value is guaranteed to be positive.
(6.2.5/3).

-Mike


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

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