代码:
#include<stdio.h>
#define SIZE 50
int main()
{
char hello[SIZE];
puts("hello");
printf("hello> ");
scanf("%s\n", &hello);
printf("%s\n", hello);
return 0;
}
运行之后没有反应!
scanf("%s\n", &hello) 这里输入的是字符串,不需要取地址,同时不需要加\n,如果加\n,输入时需要回车两次。
修改后代码如下,结果已验证:
#include<stdio.h>
#define SIZE 50
int main()
{
char hello[SIZE];
puts("hello");
printf("hello> ");
scanf("%s", hello);
printf("%s\n", hello);
return 0;
}
结果验证:
hello
hello> asdf
asdf