打印

linux下gets能用吗??

linux下gets能用吗??

#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.

问题出错在哪???

TOP

引用:
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.
不是说 这个函数很危险 ,不应该使用!

TOP

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

TOP

gets: stack overflow hole

TOP