EOF之后的getchar() [英] getchar() after EOF

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

问题描述

如果对getchar()的调用返回EOF,如果进行了另一个getchar()调用,是否定义了行为

?请问

再次返回EOF?

我问的原因是:我是否有一个使用

getchar的函数()反复,并在一些字节后返回EOF,

我是否需要在那里处理EOF的功能,

或者,我可以等到下一次我的函数执行,

并在那里处理,如果第一次调用将返回EOF

到getchar()。


谢谢!


/ Michael

解决方案

文章< Wz ******* **********@newsb.telia.net> ;,

Michael Brennan< br ************ @ gmail.com>写道:

如果调用getchar()返回EOF,是否定义了另一个getchar()调用的行为?它会再次返回EOF吗?


是的。虽然在我阅读C89时,它可能会合理地设置

错误指示器。


我问的原因是:如果我有一个重复使用
getchar()的函数,它在一些字节后返回EOF,
我是否需要在那里处理EOF的函数,
或者,我可以等到下一个我的功能执行的时间,
并在那里处理,如果第一次调用将返回EOF,则getchar()。




什么会你使用EER中返回的EOF'

来电吗?如果你打算存储它们,那么请记住

EOF是一个int,而不是一个字母

-

我还很年轻那些日子,但我也很朦胧。

- Christopher Priest


>如果对getchar()的调用返回EOF,如果进行了另一个getchar()调用,是否定义了

行为?它会再次返回EOF吗?




标准的7.19.7.6这样说:

" getchar函数返回输入流中的下一个字符

由stdin指向。如果流位于文件末尾,则设置流的文件结尾

指示符并且getchar返回EOF。


我相信一个流,一旦在文件末尾保留在文件末尾

,除非发生反向定位。但是,我在标准中找不到关于此的直接声明。


文章< e6 ******** @ dispatch.concentric.net>,

Jim Cook< co **** @ strobedata.com>写道:

7.19.7.6标准说:
" getchar函数返回stdin指向的输入流中的下一个字符。如果流位于文件结尾,则设置流的文件结束
指示符,并且getchar返回EOF。
我相信,一旦文件末尾的流仍然保留在文件结尾处
除非发生反向定位。


虽然clrerror()会清除EOF指标以及

错误指示。

但是,我找不到一个在标准中直接说明这一点。



-

编程就是在你忙于制定其他计划的时候发生的事情。 />


If a call to getchar() returns EOF, is the behavior
defined if another getchar() call is made? Will it
return EOF again?

The reason I''m asking: if I have a function that uses
getchar() repeatedly, and it returns EOF after some bytes,
do I need the function to handle the EOF right there,
or, can I just wait until the next time my function executes,
and handle it there, if EOF will be returned by the first call
to getchar().

Thanks!

/Michael

解决方案

In article <Wz*****************@newsb.telia.net>,
Michael Brennan <br************@gmail.com> wrote:

If a call to getchar() returns EOF, is the behavior
defined if another getchar() call is made? Will it
return EOF again?
Yes. Though in my reading of C89, it might plausibly set the
error indicator as it does so.

The reason I''m asking: if I have a function that uses
getchar() repeatedly, and it returns EOF after some bytes,
do I need the function to handle the EOF right there,
or, can I just wait until the next time my function executes,
and handle it there, if EOF will be returned by the first call
to getchar().



What would you do with the EOF''s returned in the itermediate
calls? If you were planning on storing them, then remember that
EOF is an int, not a char
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest


> If a call to getchar() returns EOF, is the behavior

defined if another getchar() call is made? Will it
return EOF again?



7.19.7.6 of the standard says this:
"The getchar function returns the next character from the input stream
pointed to by stdin. If the stream is at end-of-file, the end-of-file
indicator for the stream is set and getchar returns EOF."

I believe that a stream, once at end-of-file remains at end-of-file
unless reverse positioning happens. However, I cannot find a direct
statement about this in the standard.


In article <e6********@dispatch.concentric.net>,
Jim Cook <co****@strobedata.com> wrote:

7.19.7.6 of the standard says this:
"The getchar function returns the next character from the input stream
pointed to by stdin. If the stream is at end-of-file, the end-of-file
indicator for the stream is set and getchar returns EOF." I believe that a stream, once at end-of-file remains at end-of-file
unless reverse positioning happens.
Though clrerror() will clear the EOF indicator as well as the
error indicator.
However, I cannot find a direct
statement about this in the standard.


--
Programming is what happens while you''re busy making other plans.


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

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