我正在尝试从键盘读取两个字符串并打印它们。为什么会printf("read 1st\n")
在秒后运行scanf()
?
#include <stdio.h>
int main(void)
{
char str[20];
char str2[20];
scanf("%s", str);
printf("read 1st\n");
scanf("%s", str2);
printf("read 2nd\n");
printf("str: %s\nstr2: %s\n", str, str2);
return 0;
}
Expected:
foo
read 1st
bar
read 2nd
str: foo
str2: bar
Actual:
foo
bar
read 1st
read 2nd
str:foo
str2:bar