gcc 4.1上的getchar()行为 [英] getchar() behaviour on gcc 4.1
问题描述
这是我使用的简单代码片段...
#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屋!