main()
{
int d,a;
printf("Enter the digit :");
scanf("%d",&d);
printf("Enter another digit :");
scanf("%d",&a);
}
输出: 输入数字:10 输入另一个数字:10
main()
{
int d;
char a[10];
printf("Enter the digit :");
scanf("%d ",&d);
printf("Enter another digit :");
scanf("%s ",a);
}
输出:
Enter the digit : 10
waiting for stdin
谁能解释一下 scanf("%d",&a)
和 scanf("%d ",&a)
之间的区别?为什么在 scanf
语句中添加一个空格会导致它等待 stdin?
最佳答案
scanf 格式字符串中的空格匹配任何 空格字符,不仅是空格,甚至是多次,所以如果你按回车,它就是匹配字符串的一部分。如果您按 Ctl+D,它应该可以工作。
关于c - 解释 scanf 中没有空格和 scanf 中有空格有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12704907/