我在调用scanf()时输入Ctrl-D(EOF),然后忽略下一个scanf。
#include <stdio.h>
int main()
{
int input;
scanf("%d", &input);//I press Ctrl-D when this line
scanf("%d", &input);//this line just passed. not read my input. why?
return 0;
}
我想第二次调用scanf()获得输入。
有什么问题吗?
最佳答案
看来您的代码还可以。唯一的想法是要记住在两个输入数字的末尾都按“返回”。我以“更好”的方式重写了您的代码:
#include <stdio.h>
int main(){
int input1,input2;
printf("Digit the first number: ");
scanf("%i", &input1);//Press return at the end
printf("Digit the second number: ");
scanf("%i", &input2);//Press return at the end
printf("input1:%i\tinput2:%i\n",input1,input2);
return 0;
}