gcc不支持标准c的gets puts函数

4006阅读 9评论2011-01-17 非洲乌龟
分类:C/C++

一段c源程序代码如下:#include"stdio.h"
main()
{
char st[15];
printf("input string:\n");
gets(st);
puts(st);
}
编译执行报如下错误,
(.text+0x24): warning: the `gets' function is dangerous and should not be used.
该提示说明linux下gcc不支标准c的gets,puts函数,可以用gcc fgets,fputs分别代替gets,puts,其格式及
更改如下:
#include "stdio.h"
main()
{
char st[15];
printf("input string:\n");
fgets(st,15,stdin); /*stdin 意思是键盘输入*/
fputs(st,stdout);   /*stdout标准输出*/
}
这样就不会报错了。
上一篇:时间过得好快
下一篇:Linux 脚本编写基础

文章评论