写入硬盘,并检查错误退出(1)? [英] Writing to the hard disk, and checking for error to exit(1)?

查看:76
本文介绍了写入硬盘,并检查错误退出(1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我在很长一段时间内没有做过C prorgamming,我已经忘记了

这样做了。)


我''我正在写一个程序,它用a +打开一个文件,我想

能够继续写入这个文件,但是我希望程序能够

exit(1)如果磁盘已满或其他写入失败。我想

来看一个C代码示例。提前致谢!

(I''ve not done C prorgamming in such a long time, I have forgotten how
to do this.)

I''m writing a program, where it fopens a file with "a+", and I want to
be able to continue writing to this file, but I want the program to
exit(1) if the disk is full or some other write failure. I would like
to see a C code example. Thanks in advance!

推荐答案

eastcoastguyz说:
eastcoastguyz said:

(I在这么长的时间里,我没有做过C prorgamming,我已经忘记了

这样做了。)


我正在写一个程序,它用a +打开一个文件,我想

能够继续写入这个文件,但是我想要程序

退出( 1)如果磁盘已满或其他一些写入失败。我想

来看一个C代码示例。提前致谢!
(I''ve not done C prorgamming in such a long time, I have forgotten how
to do this.)

I''m writing a program, where it fopens a file with "a+", and I want to
be able to continue writing to this file, but I want the program to
exit(1) if the disk is full or some other write failure. I would like
to see a C code example. Thanks in advance!



查找ferror()。 Cf< stdio.h>


另外考虑使用EXIT_FAILURE而不是1. Cf< stdlib.h>


-

Richard Heathfield

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

电子邮件:rjh在上述域名, - www。

Look up ferror(). Cf <stdio.h>

Also consider using EXIT_FAILURE instead of 1. Cf <stdlib.h>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


12月13日晚上7:33,Richard Heathfield< ; r ... @ see.sig.invalidwrote:

< snip>
On Dec 13, 7:33 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>

查找ferror()。 Cf< stdio.h>


另外考虑使用EXIT_FAILURE而不是1. Cf< stdlib.h>


-

Richard Heathfield

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

电子邮件:rjh在上述域名, - www。
Look up ferror(). Cf <stdio.h>

Also consider using EXIT_FAILURE instead of 1. Cf <stdlib.h>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.



HPUX存在(仍然是?)问题,如果磁盘已满,则fprintf()将阻止

,因此可能不总是工作。这种行为

是否符合标准?我只发现fprintf函数返回

传输的字符数,如果输出或

编码错误,则返回负值。

-

WYCIWYG - 你得到的是什么

There was (still is?) an issue with HPUX where fprintf() would block if
the disk got full, so this might not always work. Does this behaviour
conform to the Standard? I only found "The fprintf function returns the
number of characters transmitted, or a negative value if an output or
encoding error occurred."
--
WYCIWYG - what you C is what you get


matevzb写道:
matevzb wrote:

12月13日晚上7:33,Richard Heathfield< r ... @ see.sig.invalidwrote:

< snip>
On Dec 13, 7:33 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>

查找ferror()。 Cf< stdio.h>


另外考虑使用EXIT_FAILURE而不是1. Cf< stdlib.h>
Look up ferror(). Cf <stdio.h>

Also consider using EXIT_FAILURE instead of 1. Cf <stdlib.h>



HPUX存在(仍然是?)问题,如果磁盘已满,则fprintf()将阻止

,这可能是不总是工作。这种行为

是否符合标准?我只发现fprintf函数返回

传输的字符数,如果输出或

编码错误,则返回负值。


There was (still is?) an issue with HPUX where fprintf() would block if
the disk got full, so this might not always work. Does this behaviour
conform to the Standard? I only found "The fprintf function returns the
number of characters transmitted, or a negative value if an output or
encoding error occurred."



它符合标准。但话说回来,

在每个陈述后等待三天的实施也可以符合标准。

It can conform to the standard. But then again, an implementation that
waits three days after each statement can also conform to the standard.


这篇关于写入硬盘,并检查错误退出(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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