首页 > 编程语言 > 详细

为什么在c语言中使用gets函数是危险的

时间:2016-09-06 19:53:12      阅读:199      评论:0      收藏:0      [点我收藏+]

 

 

If you have code like this:

char s[10];
gets( s );

and you type in more than 10 characters when the program is run, you will overflow the buffer, causing undefined behaviour. The gets() function has no means of preventing you typing the characters and so should be avoided. Instead you should use fgets(), which allows you to limit the number of characters read, so that the buffer does not overflow.:

char s[10];
fgets( s, 10, stdin );

为什么在c语言中使用gets函数是危险的

原文:http://www.cnblogs.com/litifeng/p/5846813.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!