ungetc函数 [英] ungetc

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

问题描述

为什么允许ungetc(EOF,pfile)这么危险; (关闭输入

流)?

Why is so danger to allow ungetc(EOF, pfile); (for close the imput
stream) ?

推荐答案

av写道:
av wrote:

为什么允许ungetc(EOF,pfile)这么危险; (关闭输入

流)?
Why is so danger to allow ungetc(EOF, pfile); (for close the imput
stream) ?



ungetc将字符推回到流中,EOF不是字符。

我们已经有fclose关闭流。

ungetc pushes characters back onto the stream, EOF isn''t a character.
We already have fclose for closing a stream.


av写道:
av wrote:

为什么允许ungetc(EOF,pfile)这么危险; (关闭输入

流)?
Why is so danger to allow ungetc(EOF, pfile); (for close the imput
stream) ?



EOF不是任何流中的字符。试图将'推''回到

流是没有意义的。


鉴定..

如果(ch == EOF)

{
/ *假设没有错误,到达此处意味着之前的呼叫

getc(pfile)是流中的最后一个字符。

* /

}

-

Joe Wright

所有东西都应尽可能简单,但不能简单。

--- Albert Einstein ---

EOF is not a character in any stream. Trying to ''push'' it back onto the
stream doesn''t make sense.

Given..
int ch;
ch = getc(pfile);
if (ch == EOF)
{
/* Assuming no error, getting here means the the previous call to
getc(pfile) was the last character in the stream.
*/
}
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---


" Joe Wright" < jo ******** @ comcast.netwrote in message

news:q - ********************* ********* @ comcast.com ...
"Joe Wright" <jo********@comcast.netwrote in message
news:q-******************************@comcast.com...

av写道:
av wrote:

>为什么允许ungetc(EOF,pfile)这么危险; (关闭imput
流)?
>Why is so danger to allow ungetc(EOF, pfile); (for close the imput
stream) ?



EOF不是任何流中的字符。试图将'推''回到

流是没有意义的。


鉴定..

如果(ch == EOF)

{
/ *假设没有错误,到达此处意味着之前的呼叫

getc(pfile)是流中的最后一个字符。

* /

}


EOF is not a character in any stream. Trying to ''push'' it back onto the
stream doesn''t make sense.

Given..
int ch;
ch = getc(pfile);
if (ch == EOF)
{
/* Assuming no error, getting here means the the previous call to
getc(pfile) was the last character in the stream.
*/
}



嗯,这有点道理。 C标准要求

ungetc接受EOF作为第一个参数(并返回失败代码

EOF)。这支持了偷看。你首先在一个文件上循环的成语

偷看一个角色(获取/取消)然后决定是否消费

吧。


PJ Plauger

Dinkumware,Ltd。
http:// www.dinkumware.com


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

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