warning: the `gets' function is dangerous and should not be used.

2023-04-07编程技术121527

LINUX下编译C程序时,出现了:
warning: the `gets' function is dangerous and should not be used.

原因:Linux 下gcc编译器不支持gets()这个函数,解决办法是使用 fgets

fgets()函数的基本用法为:

fgets(char * s,int size,FILE * stream);

//eg:可以用fgets(tempstr,10,stdin)

//tempstr 为char[]变量,10为要输入的字符串长度,stdin为从标准终端输入。

如:

以前:char  str[100];

  gets(str);

修改之后:

char str[100];
fgets(str,100,stdin);

注意:
gets从终端读入是的字符串是用\0结束的,而fgets是以\n结束的(一般输入都用ENTER结束)

warning: the `gets' function is dangerous and should not be used.的相关教程结束。

本文地址:https://www.ufcn.cn/tutorials/2424035.html

如非特殊说明,本站内容均来自于网友自主分享,概不代表本站观点,如有任何问题我们都将在收到反馈后的第一时间进行处理!