Linux编程时使用gcc编译.c出现以下问题warning: the `gets' function is dangerous and should not be used.

Linux编程时使用gcc编译.c出现以下问题

[root@localhost final1]# gcc -pthread client.c
/tmp/ccSuK4v5.o: In function `writedata':
client.c:(.text+0xb2a): warning: the `gets' function is dangerous and should not be used.

解决方法如下:
使用fgets,同时对程序做稍微的修改即可.
fgets()函数的基本用法:fgets(char * s,int size,FILE * stream);//eg:可以用fgets(tempstr,10,stdin)//tempstr 为char[]变量,10为要输入的字符串长度,stdin为从标准终端输入。

原因:程序中使用了gets()函数,Linux 下gcc编译器不支持这个函数

猜你喜欢

转载自blog.csdn.net/qq_40120951/article/details/85007602