linux下gets能用吗??
#include<stdio.h>#include<string.h>
main()
{
char st1="My name is:";
int st2;
printf("please insert your name\n");
gets(st2);
strcat(st1,st2);
puts(st1);
}
gcc -o 之后
7.14.c: 在函数 ‘main’ 中:
7.14.c:8: 警告:传递参数 1 (属于 ‘gets’)时在不兼容的指针类型间转换
7.14.c:9: 警告:传递参数 2 (属于 ‘strcat’)时在不兼容的指针类型间转换
/tmp/cc96MPyp.o: In function `main':
7.14.c:(.text+0x24): warning: the `gets' function is dangerous and should not be used.
问题出错在哪???
7.14.c:8: 警告:传递参数 1 (属于 ‘gets’)时在不兼容的指针类型间转换
7.14.c:9: 警告:传递参数 2 (属于 ‘strcat’)时在不兼容的指针类型间转换
不是说得很清楚了吗??
gets的参数应该是 char *
strcat 的参数是 char * ,char *
当然,如果gcc有了新的改变我就不知道了!!
7.14.c.text+0x24): warning: the `gets' function is dangerous and should not be used.
不是说 这个函数很危险 ,不应该使用! 哦,原来是这样!!好的试一下 gets: stack overflow hole
页:
[1]