FERROR() [英] ferror()

查看:146
本文介绍了FERROR()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如果我试图读取文件末尾,feof()将返回非零

值。但我可以保证ferror()为0吗?简而言之,在某些实现中是否会设置错误

指标只是因为设置了文件结尾

指标?对标准的搜索没有揭示eof是否被视为错误。 (如果说的话,请引用标题

数字)。


谢谢


Stephen Howe

Hi,

If I attempt to read past the end of a file, feof() will return a non-zero
value. But can I guarantee that ferror() is 0? In short, will the error
indicator be set in some implementations just because the end-of-file
indicator is set? A search on the standard does not reveal if eof is
regarded as an "error" (if does say something, please quote the heading
numbers).

Thanks

Stephen Howe

推荐答案

" Stephen Howe" < NO ********** @ dial.pipex.com>写道:
"Stephen Howe" <NO**********@dial.pipex.com> wrote:


如果我试图读取文件末尾,feof()将返回非零值。但我可以保证ferror()为0吗?简而言之,仅仅因为设置了文件结尾
指示符,是否会在某些实现中设置错误
指示符?对标准的搜索没有揭示eof是否被视为错误。 (如果说的话,请引用标题
数字)。
Hi,

If I attempt to read past the end of a file, feof() will return a non-zero
value. But can I guarantee that ferror() is 0? In short, will the error
indicator be set in some implementations just because the end-of-file
indicator is set? A search on the standard does not reveal if eof is
regarded as an "error" (if does say something, please quote the heading
numbers).




使用feof()没什么意义。无论你使用什么函数来读取数据都会指示何时发生文件结束或i / o

错误,例如:


while(fread(...,fp)!= 0){

...

}


当循环退出时,你肯定知道一个或另一个

条件已经发生,但一般来说,你想要采取的唯一例外是错误,


if(ferror(fp)){

... / *处理错误* /

}


如果没有指示错误,程序会继续运行,因为

预期文件结束条件。


如果确实发生了错误,如果feof()是真的那么没有区别




-

Floyd L. Davidson< http://web.newsguy.com/floyd_davidson>

Ukpeagvik(阿拉斯加州巴罗市) fl *** @ barrow。 com


In< 3f ************ **********@reading.news.pipex.net> Stephen Howe < NO ********** @ dial.pipex.com>写道:
In <3f**********************@reading.news.pipex.net > "Stephen Howe" <NO**********@dial.pipex.com> writes:
如果我试图读取文件末尾,feof()将返回非零值。但我可以保证ferror()为0吗?简而言之,仅仅因为设置了文件结尾
指示符,是否会在某些实现中设置错误
指示符?对标准的搜索没有揭示eof是否被视为错误。 (如果说的话,请引用标题
号码。)
If I attempt to read past the end of a file, feof() will return a non-zero
value. But can I guarantee that ferror() is 0? In short, will the error
indicator be set in some implementations just because the end-of-file
indicator is set? A search on the standard does not reveal if eof is
regarded as an "error" (if does say something, please quote the heading
numbers).




到达文件末尾不被视为错误。


OTOH,我无法弄清楚你问题的实际方面。为什么一旦你到达文件末尾的
后,
是否需要保证关于恐怖返回值?


In练习,到达文件末尾是输入函数失败的最常见原因。因此,如果输入函数调用返回

a失败指示(EOF或空指针),您只需调用feof()来确定它是否为eof条件或I / O错误。在这种情况下,你根本不需要调用ferror()。


ferror()通常对输出流非常有用我不想

打扰检查每个输出电话。如果在调用fclose()之前,

ferror()返回零,你可以假设一切都很好,直到那个

点(如果你没有对它执行任何操作)流将重置

流的错误指示器。)


Dan

-

Dan Pop

DESY Zeuthen,RZ集团

电子邮件: Da *** **@ifh.de


Dan Pop写道:


(关于feof()和ferror的剪辑( ))
Dan Pop wrote:

(snip regarding feof() and ferror())
实际上,到达文件末尾是输入功能失败的最常见原因。因此,如果输入函数调用返回失败指示(EOF或空指针),则只需调用feof()以确定它是eof条件还是I / O错误。在这种情况下,你根本不需要调用ferror()。
ferror()通常对输出流有用,当你不想打扰检查每个输出调用时。如果,在调用fclose()之前,
ferror()返回零,你可以假设一切都很好,直到那个点(如果你没有对该流进行任何操作就会重置
流的'错误指示符)。
In practice, reaching the end of file is the most common reason for the
failure of an input function. So, if the input function call returns
a failure indication (EOF or a null pointer), you simply call feof() to
figure out whether it was an eof condition or an I/O error. You don''t
need to call ferror() at all in this case. ferror() is usually useful for output streams, when you don''t want to
bother checking each and every output call. If, before calling fclose(),
ferror() returns zero, you can assume that everything was fine up to that
point (if you have performed no actions on that stream that would reset
the stream''s error indicator).




难道你也不能检查fclose()的返回值吗?


我相信在C外部缓冲的情况下,所有数据都不一定会被推到磁盘上,并且磁盘已满了

条件仍然可能发生。


我相信只有一小部分程序正确检查输出文件的返回状态




- 格伦



Shouldn''t you also check the return value of fclose()?

I believe that in the case of buffering external to C, all the data
won''t necessarily be pushed all the way to the disk, and a disk full
condition could still occur.

I do believe that only a small fraction of programs correctly check
the return status on output files.

-- glen


这篇关于FERROR()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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