找回密码
 注册
查看: 2237|回复: 3

linux下gets能用吗??

[复制链接]
发表于 2007-1-9 22:32:00 | 显示全部楼层 |阅读模式
#include<stdio.h>
#include<string.h>
main()
{
char st1[30]="My name is:";
int st2[10];
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.

问题出错在哪???
发表于 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.

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

使用道具 举报

 楼主| 发表于 2007-1-10 21:24:36 | 显示全部楼层
哦,原来是这样!!好的试一下
回复

使用道具 举报

发表于 2007-1-11 12:16:27 | 显示全部楼层
gets: stack overflow hole
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2025-2-6 07:09 , Processed in 0.021542 second(s), 16 queries .

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表