getchar()的行为 [英] The behaviour of getchar()

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

问题描述



你好,


通常接受对getchar()函数的调用暂停

执行目前的计划。我没有在标准中找到任何关于这个

行为的描述(我可能已经错过了它)。


我想知道它只是一个''大多数系统的常见行为,以及

对ENTER键的命令是强制性的。


感谢您阅读我。


-

-ed- em ***** *****@noos.fr [在回答我之前删除YOURBRA]

C语言常见问题解答: http://www.eskimo.com/~scs/C-faq/top.html

C-reference: http://www.dinkumware .com / manuals / reader.aspx?lib = cpp

FAQ de fclc: http://www.isty-info.uvsq.fr/~rumeau/fclc/


Hi there,

It is commonly accepted that a call to the getchar() function suspends the
execution of the current program. I have not found any description of this
behaviour in the standard (I may have missed it).

I was wondering wether it was just a ''common'' behaviour of most systems, and
wether the hit of the ENTER key was mandatory.

Thanks for having read me.

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

推荐答案

Emmanuel Delahaye< em ********** @ noos.fr>潦草地写道:
Emmanuel Delahaye <em**********@noos.fr> scribbled the following:
你好,
人们普遍认为,对getchar()函数的调用会暂停当前程序的执行。我没有在标准中找到任何关于此行为的描述(我可能已经错过了它)。
我想知道它只是大多数系统的常见行为,并且
对ENTER键的命中是强制性的。
感谢你读过我。
Hi there, It is commonly accepted that a call to the getchar() function suspends the
execution of the current program. I have not found any description of this
behaviour in the standard (I may have missed it). I was wondering wether it was just a ''common'' behaviour of most systems, and
wether the hit of the ENTER key was mandatory. Thanks for having read me.




我认为标准只说getchar()暂停执行

直到一个角色出现在stdin上。那个角色来到stdin

来自C'的业务。具体来说,C什么都不知道输入密钥的
。这是一个特定于操作系统的缓冲机制,在C看到任何字符提示之前发生了


尝试从不包含EOL的文件重定向stdin(End Of线路)

标记,你会看到getchar()工作正常而不读任何

输入键。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰----- --- \

\ - http:// www.helsinki.fi/~palaste ---------------------规则! -------- /

我们是女性。我们有双重标准可以实现。

- Ally McBeal



I think that the standard only says that getchar() suspends execution
until a character appears on stdin. Where that character came to stdin
from is none of C''s business. Specifically, C knows nothing whatsoever
of "ENTER keys". It''s an OS-specific buffering mechanism that happens
before C sees any hint of the characters.
Try redirecting stdin from a file that contains no EOL (End Of Line)
markers and you''ll see getchar() works just fine without reading any
"ENTER keys".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"We''re women. We''ve got double standards to live up to."
- Ally McBeal


Emmanuel Delahaye写道:
Emmanuel Delahaye wrote:

你好,

通常认为调用getchar()
函数会暂停当前程序的执行。

Hi there,

It is commonly accepted that a call to the getchar()
function suspends the execution of the current program.




所有函数调用都是这样的。


N869

6.2.4对象的存储持续时间

[#4]

输入一个封闭的块或调用一个函数暂停,

但不会结束,执行当前块。


-

pete



All function calls do that.

N869
6.2.4 Storage durations of objects
[#4]
Entering an enclosed block or calling a function suspends,
but does not end, execution of the current block.

--
pete




" Emmanuel Delahaye" < EM ********** @ noos.fr>在消息中写道

"Emmanuel Delahaye" <em**********@noos.fr> wrote in message

通常接受对getchar()函数的调用暂停>
执行当前程序。我没有在标准中找到任何关于此行为的描述(我可能已经错过了它)。

It is commonly accepted that a call to the getchar() function suspends > the execution of the current program. I have not found any description of this behaviour in the standard (I may have missed it).



标准是符合实现的正式规范,它是

不是为教C而设计的。

在这种情况下,你在学习C

时会遇到的每一个实现都会有一个键盘,一个行缓冲区和一些设施在输入之前编辑

行。显然这需要暂停执行,直到

用户进入该行。

但是标准并没有强迫计算机以这种方式工作 - 事实上

将文件重定向到stdin并在

自动输入上运行程序的情况并不少见。


The standard is a formal specification of a conforming implementation, it is
not designed to teach C.
In this case every implementation you will come across whilst learning C
will have a keyboard, a line buffer, and some facilities to edit the line
before entering it. Obviously this entails suspending execution until the
user enters the line.
However the standard doesn''t force the computer to work that way - in fact
it is not uncommon to redirect a file to stdin and run a program on
automatic input.


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

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