我想的getchar两次,但我不能 [英] i want to getchar twice but i cant
问题描述
int main()
{
int r, c;
r = getchar();
c = getchar();
putchar(r);
putchar(c);
printf("\n");
return(0);
}
它读取后 - [R
,方案产出研究
和退出。我希望它要求 C
和投入,但怎么来它没有这样做呢?
After it reads in r
, the program outputs r
and quits. I want it to ask for c
and input it but how come it doesnt do that?
推荐答案
您在同一行中输入字符,或两行?
Are you entering the characters on the same line, or on 2 lines?
的getchar()
会等到你preSS进入,然后开始分析的字符。如果您已经在2个不同的行中输入两个字符,它会读取第一个字符的然后 \\ n
字符的
getchar()
will wait until you press enter, and then start parsing the characters. If you have entered 2 characters on 2 different lines, it will read the first character and then the \n
character.
我的意思是,下面的输入:
What I mean is, the following input:
a
b
等同于一\\ NB
。
的getchar()
将抓住 \\ n
而不是乙
,并打印 A \\ n \\ n
。
getchar()
will grab the \n
instead of b
, and print a\n\n
.
您想要输入两个字符,只有按下回车键。
You want to type both characters, and only then hit enter.
这篇关于我想的getchar两次,但我不能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!