Chinaunix首页 | 论坛 | 博客
  • 博客访问: 170524
  • 博文数量: 40
  • 博客积分: 2697
  • 博客等级: 少校
  • 技术积分: 750
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-27 16:55
文章分类

全部博文(40)

文章存档

2012年(1)

2011年(13)

2010年(26)

分类: C/C++

2011-01-17 14:21:18

一段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标准输出*/
}
这样就不会报错了。
阅读(3823) | 评论(9) | 转发(0) |
0

上一篇:时间过得好快

下一篇:Linux 脚本编写基础

给主人留下些什么吧!~~

chinaunix网友2011-08-28 08:28:55

warning: the `gets' function is dangerous and should not be used. GCC在警告你:gets()很危险(容易导致访问越界),不建议使用。(而不是不支持!!)

chinaunix网友2011-08-28 08:26:09

文档已经建议你别用gets()了,你还在用。

chinaunix网友2011-08-28 08:24:41

BUGS Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

chinaunix网友2011-03-09 11:35:10

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2011-01-28 01:21:20

http://bbs.chinaunix.net/thread-1686753-1-1.html