什么是获取和scanf区别? [英] What's the difference between gets and scanf?

查看:104
本文介绍了什么是获取和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 a whitespace, newline or EOF

获得()认为是空格输入字符串的一部分,在遇到结束输入换行 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屋!

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