问题描述
大家好,
每当我使用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.
推荐答案
gets()不允许你限制输入量,这意味着
可能会溢出输入所在的缓冲区放置。
-
John Gordon A是Amy,他从楼梯上摔下来
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"
你可以解释一下b / w scanf()和gets()的差异吗??
谢谢,
Jayapal
Can u explain the differences b/w the scanf() and gets() ..?
Thanks,
Jayapal
你能解释一下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()是危险的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!