这是简单的代码。我正在接受输入,打印它,然后再次接受并再次打印。
第二次不让我输入。
谁能解释一下为什么?
#include "stdio.h"
int main()
{
char buff[50];
printf("Enter a String\n");
scanf("%[^\n]s",buff);
puts(buff);
printf("Enter another String\n");
scanf("%[^\n]s",buff);
puts(buff);
return 0;
}
输出:
Enter a String
Hello // This I have entered
Hello // This is the output
Enter another String
Hello // This I haven't entered, It automatically takes this.
最佳答案
在第二个 scanf() 中,在输入说明符的开头放置一个空格:
scanf(" %[^\n]s",buff);
^^^
这将吃掉当前第二次满足 scanf 的字符,并允许您输入第二个字符串。
关于c - 输出自 Action 为C中的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779192/