为什么使用gets()是危险的。 [英] why the usage of gets() is dangerous.

查看:237
本文介绍了为什么使用gets()是危险的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


每当我使用gets()函数时,gnu c编译器会发出

警告,表明使用gets是危险的( )。为什么......?


问候,

jayapal。

Hi all,

Whenever I use the gets() function, the gnu c compiler gives a
warning that it is dangerous to use gets(). why...?

regards,
jayapal.

推荐答案

在< 2f ********************************** @ n20g2000hsh。 googlegroups.comjayapal< ja ******** @ gmail.comwrites:
In <2f**********************************@n20g2000hsh. googlegroups.comjayapal <ja********@gmail.comwrites:

每当我使用gets()函数时,gnu c编译器会给出一个

警告使用gets()是危险的。为什么...?
Whenever I use the gets() function, the gnu c compiler gives a
warning that it is dangerous to use gets(). why...?



gets()不允许你限制输入量,这意味着
可能会溢出输入所在的缓冲区放置。


-

John Gordon A是Amy,他从楼梯上摔下来
go **** @ panix.com B代表巴兹尔,被熊袭击

- 爱德华·戈瑞,The Gashlycrumb Tinies

gets() does not allow you limit the amount of input, which means it
can potentially overflow the buffer into which the input is placed.

--
John Gordon A is for Amy, who fell down the stairs
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"


11月16日晚上10点10分,John Gordon< gor ... @ panix.comwrote:
On Nov 16, 10:10 pm, John Gordon <gor...@panix.comwrote:

gets()不允许你限制输入量,这意味着
可能会溢出放入输入的缓冲区。
gets() does not allow you limit the amount of input, which means it
can potentially overflow the buffer into which the input is placed.



你可以解释一下b / w scanf()和gets()的差异吗??


谢谢,

Jayapal

Can u explain the differences b/w the scanf() and gets() ..?

Thanks,
Jayapal


jayapal< ja ******** @ gmail.comwrites:
jayapal <ja********@gmail.comwrites:

11月16日晚上10点10分,John Gordon< gor ... @ panix.comwrote:
On Nov 16, 10:10 pm, John Gordon <gor...@panix.comwrote:

> gets()不允许你限制输入量,这意味着它可能会溢出输入所在的缓冲区。
>gets() does not allow you limit the amount of input, which means it
can potentially overflow the buffer into which the input is placed.



你能解释一下scanf()和gets()的差异吗?


Can u explain the differences b/w the scanf() and gets() ..?



大概你的意思是字符串输入?使用''scanf("%[^ \ n]",buf)''

与''gets''有同样的问题。但是scanf可以保存(差不多)

,因为它允许有限的输入操作:


char buf [100];

...

if(scanf("%99 [^ \ n]",buf)== 1)...


-

Ben。

Presumably you mean for string input? Using ''scanf("%[^\n]", buf)''
has the same problem as ''gets''. But scanf can be saved (just about)
since it permits a bounded input operation:

char buf[100];
...
if (scanf("%99[^\n]", buf) == 1) ...

--
Ben.


这篇关于为什么使用gets()是危险的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆