happytofly 发表于 2007-1-9 22:32:00

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.

问题出错在哪???

wkt 发表于 2007-1-10 11:17:00


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.

不是说 这个函数很危险 ,不应该使用!

happytofly 发表于 2007-1-10 21:24:36

哦,原来是这样!!好的试一下

cybershot 发表于 2007-1-11 12:16:27

gets: stack overflow hole
页: [1]
查看完整版本: linux下gets能用吗??