我有一个问题。当我运行它时,它只是垃圾邮件“更大”,而不是让我写入 scanf。有人可以尝试解释一下原因以及我可以采取哪些措施来解决它吗?
#include <stdio.h>
#include <time.h>
int main(){
int rn, n=0;
rn=rand();
while (n!=rn){
scanf("%n", &n);
if (n<rn)
printf("\nBigger\n");
else if (n>rn)
printf("\nSmaller\n");
}
printf("\nCorrect\n");
}
最佳答案
%n
不正确。您可能需要 %d
并且应该检查 scanf()
返回的内容以检查是否有错误。
来自man scanf
:
n Nothing is expected; instead, the number of characters consumed thus far from the input is stored through the next pointer, which must be a pointer to int. This is not a conversion, although it can be suppressed with the * flag.
关于c - Scanf 不等待输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49844506/