使用的是 CentOS gcc编译下面程序 显示
warning: the `gets' function is dangerous and should not be used.
问题出在程序中使用了 gets Linux 下gcc编译器不支持这个函数,解决办法是使用 fgets
fgets()函数的基本用法为: fgets(char * s,int size,FILE * stream);
/* 代码实现 */
#include <stdio.h>
int main ( ) {
char name[20];
printf("\n 输入任意字符 : ");
fgets(name, 20, stdin);//stdin 意思是键盘输入
fputs(name, stdout); //stdout 输出
return 0;
}
======================================

本文介绍了一个使用CentOS gcc编译器时遇到的警告问题,即使用gets函数时的危险性提示。文章提供了将gets替换为fgets的方法,并给出了具体的代码示例。
704

被折叠的 条评论
为什么被折叠?



