来自printf的EOF [英] EOF from printf

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

问题描述

当printf时函数返回EOF?将printf永远不会失败?

When "printf" function returns "EOF"? Will "printf" ever fail?

推荐答案

" v4vijayakumar" < vi ****************** @ gmail.comwrites:
"v4vijayakumar" <vi******************@gmail.comwrites:

当" printf"函数返回EOF?将printf永远失败?
When "printf" function returns "EOF"? Will "printf" ever fail?



C99 7.19.6.3p3:


printf函数返回传输的字符数,
$ b如果发生输出或编码错误,则为$ b或负值。


负值不一定与EOF相同,而且你需要
不应该不要以为它是。


任何像样的C教科书,或者你的系统的文档,都应该为你回答




-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

C99 7.19.6.3p3:

The printf function returns the number of characters transmitted,
or a negative value if an output or encoding error occurred.

The negative value isn''t necessarily the same as EOF, and you
shouldn''t assume that it is.

Any decent C textbook, or your system''s documentation, should answer
this for you.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


3月27日,1 :12 pm,Keith Thompson< k ... @ mib.orgwrote:
On Mar 27, 1:12 pm, Keith Thompson <k...@mib.orgwrote:

" v4vijayakumar" < vijayakumar.subbu ... @ gmail.comwrites:
"v4vijayakumar" <vijayakumar.subbu...@gmail.comwrites:

当" printf"函数返回EOF?将printf永远失败?
When "printf" function returns "EOF"? Will "printf" ever fail?



C99 7.19.6.3p3:


printf函数返回传输的字符数,
$ b如果发生输出或编码错误,则为$ b或负值。


负值不一定与EOF相同,而且你需要
不应该不要以为它是。


C99 7.19.6.3p3:

The printf function returns the number of characters transmitted,
or a negative value if an output or encoding error occurred.

The negative value isn''t necessarily the same as EOF, and you
shouldn''t assume that it is.



谢谢。我试过,man 3 printf在cygwin。它说,


---

退货

`sprintf''和`asprintf''返回字节数

输出

字符串,除非结算NULL不计算在内。

`printf''和

`fprintf''返回传输的字符数。如果

出现错误

,'printf''和`fprintf''返回`EOF''和`asprintf''

返回 - 1.

sprintf没有错误返回。

---


我只是想知道,在在哪种情况下它可能会失败。


为什么它返回负值,当EOF时会满足吗?

否定

返回值是否有更多关于失败的信息?

Thanks. I tried, "man 3 printf" in cygwin. It says,

---
RETURNS
`sprintf'' and `asprintf'' return the number of bytes in
the output
string, save that the concluding `NULL'' is not counted.
`printf'' and
`fprintf'' return the number of characters transmitted. If
an error
occurs, `printf'' and `fprintf'' return `EOF'' and `asprintf''
returns -1.
No error returns occur for `sprintf''.
---

I just wanted to know, in which cases it can fail.

Why it returns negative value, when "EOF" would suffice? Does the
negative
return value has any more information for the failure?




" v4vijayakumar" < vi ****************** @ gmail.comwrote in message

news:11 ************ ********@r56g2000hsd.googlegrou ps.com ...

"v4vijayakumar" <vi******************@gmail.comwrote in message
news:11********************@r56g2000hsd.googlegrou ps.com...

当" printf"函数返回EOF?将printf永远失败?
When "printf" function returns "EOF"? Will "printf" ever fail?



在某些系统上,printf会导致数据在串行线上打印。 printf

不需要打印到电脑屏幕,在某些系统上它可以真正用于测试printf的返回值

On some systems printf causes data to be printed on a serial line. printf
doesnt need to print to a computer screen, on some systems it can be really
useful to test for the return value of printf


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

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