gcc 4.1上的getchar()行为 [英] getchar() behaviour on gcc 4.1

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

问题描述

这是我使用的简单代码片段...

#include< stdio.h>

int main(无效)

{

int ch;

do {

printf(仍然是...... \ n);

printf(" \ nnin choice ::");

ch = getchar();

} while(ch ==''y' ');

返回0;

}


输出::

[rautela @ blufox c] $ ./a.out

仍然是...


输入选择:: y

仍然是.. 。


[rautela @ blufox c] $

为什么下次没有等待我的输入?

我正在使用gcc 4.1在Fedora Core 5上编译它。

我在这里遗漏了什么吗?

解决方案

< blockquote> ./ a.out

仍然是...


输入选项:: y

仍然是...


[rautela @ blufox c]




为什么它没有等待我输入的内容xt时间?

我正在使用gcc 4.1在Fedora Core 5上编译这个。

我在这里遗漏了什么吗?


你的输入''y''等于条件,即条件变为真实

,所以它会再次询问你输入。请注意仅当

条件失败,循环将终止。


This is a simple code snippet i used ...
#include <stdio.h>
int main(void)
{
int ch;
do {
printf("still yes...\n");
printf("\nenter choice :: ");
ch = getchar();
}while(ch == ''y'');
return 0;
}

Output ::
[rautela@blufox c]$ ./a.out
still yes...

enter choice :: y
still yes...

[rautela@blufox c]$
Why didn''t it waits for my input the next time?
I am compiling this on a Fedora Core 5 using gcc 4.1.
Am i missing something here?

解决方案

./a.out
still yes...

enter choice :: y
still yes...

[rautela@blufox c]



Why didn''t it waits for my input the next time?
I am compiling this on a Fedora Core 5 using gcc 4.1.
Am i missing something here?


your input ''y'' is equal to the condition i.e the condition becomes true
,so it will again ask u the input.please note the only when the
condition fails the loop will terminate.


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

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