问题描述
这是我的代码
#include <stdio.h>
#include <stdlib.h>
int main(){
char c,d;
c=getchar();
d=getchar();
printf("%c %c",c,d);
return 0;}
在这里我要求输入 2 个输入,但在输入一个输入后它停止了。我的意思是,如果我只写一个字符并按回车键,它只会显示该字符。不要求任何进一步的输入。
但是当我同时输入两个输入然后按回车键时,它同时显示两个。
解决方法
因此,getchar()
正在接受输入的单个字符。但是如果你输入 c
后跟 enter
,你实际上是给它 2,第二个是 enter
。因此,第二个 getchar()
实际上正在接收 enter
键,因此您会在顶部输出中看到额外的空行。