字符串指针问题
请教下面代码为什么运行异常7 char *st,*st2;
8 printf("please input a string:");
10 scanf("%s",st);
13 printf("%s\n",st)
运行后提示“段错误 (核心已转储)”后就终止了。
而在第8行,或者第10行也行,在下面加“st2 = st;”就能够正常运行了,谢谢。
2013-07-03 22:27
2013-07-03 22:35
2013-07-03 23:31
2013-07-04 08:33
2013-07-04 08:53
程序代码:#include <stdio.h>
#include <stdlib.h>
int main()
{
char *st = (char *)malloc(100);
printf("please input a string:");
scanf("%s",st);
printf("%s\n",st);
free(st);
return 0;
} 
2013-07-04 09:11
2013-07-04 10:42