的getchar()只调用每个其他时间 [英] getchar() only calling every other time
问题描述
在使用标准章国米preTER,的getchar()
只运行每隔一行。
C:/>所以char a = getchar函数();
C:/>焦炭B =的getchar();
b
C:/>焦C =的getchar();
C:/>焦炭D =的getchar();
ð
我用 scanf函数时有同样的问题(%C,&安培; A)
代替;在Vim的语句将被跳过。
的printf(东西\\钠为SomethingA \\ NB的SomethingB的\\ n类型
\\ NC为SomethingC \\ n \\ n选择(A,B,C)>中);
字符字母=的getchar(); //这个语句被跳过
返回0;
当你在键盘上输入A,你先preSSA,然后preSSENTER键,对不对?因此,的getchar()
或 scanf函数(%C,....)
获得两个字符改为: A,并从换行符ENTER键。
如果您使用code在一个循环中,或者只是反反复复,第一的getchar()将读取从previous输入换行符。
While using Ch Standard Interpreter, getchar()
only runs every other line.
C:/> char a = getchar();
C:/> char b = getchar();
b
C:/> char c = getchar();
C:/> char d = getchar();
d
I have the same issue when using scanf("%c", &a)
instead; in Vim the statement is skipped.
printf("\nType of Something\nA for SomethingA\nB for SomethingB "
"\nC for SomethingC\n\nSelect (A,B,C) > ");
char letter = getchar(); // This statement gets skipped
return 0;
When you type "A" on the keyboard, you first press "A", and then you press "ENTER", right? So getchar()
or scanf("%c", ....)
gets two characters to read: "A", and the newline character from the "ENTER" key.
If you use your code in a loop, or just repeatedly, the first getchar() will read the newline character from the previous input.
这篇关于的getchar()只调用每个其他时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!