在我的代码中(在 c 中)scanf()
取一个整数值,但是当我键入一个整数并按回车键时,什么也没有发生(执行没有按预期继续进行)。我需要按下一个键,然后程序才能继续使用我首先按下的数字。
例子: 代码:
int num=0;
printf("Enter a number and see if he belong to one of the groups:");
scanf("%d\n\n",&num);
输出:
Enter a number and see if he belong to one of the groups:5(enter)
f(enter)
然后代码才继续......
最佳答案
好吧,看来你是在告诉 scanf
读取两个换行符,而不是一个:
scanf("%d\n\n", &num);
这应该给出正确的行为:
scanf("%d\n", &num);
关于c - scanf 接受 int 但仅在输入另一个 char/int 并按 enter 后才继续执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20502488/