什么是获取和scanf区别? [英] What's the difference between gets and scanf?
本文介绍了什么是获取和scanf区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在code是
scanf("%s\n",message)
VS
gets(message)
有什么区别?看来他们都得到输入信息。
what's the difference?It seems that both of them get input to message.
推荐答案
的基本区别[参考您的特定场景]
The basic difference [in reference to your particular scenario],
-
scanf()的
结束以输入当遇到空格
,换行
或EOF
scanf()
ends taking input upon encountering awhitespace
,newline
orEOF
获得()
认为是空格输入字符串的一部分,在遇到结束输入换行
或 EOF
。
gets()
considers a whitespace as a part of the input string and ends the input upon encountering newline
or EOF
.
然而,为了避免缓冲区溢出错误,以避免安全隐患,其使用更安全与fgets()
。
However, to avoid buffer overflow errors and to avoid security risks, its safer to use fgets()
.
这篇关于什么是获取和scanf区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文