个人意见:不检查scanf函数返回值的C程序员都是半吊子!

赵4老师 2013-05-27 12:23:02
跟帖同意的加分,不同意的扣分!
...全文
2144 87 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
87 条回复
切换为时间正序
请发表友善的回复…
发表回复
_明月 2015-08-04
  • 打赏
  • 举报
回复
引用 7 楼 xiaohuh421 的回复:
Returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned 这句怎么翻译的呢, 虽然单词都认识, 但是自己翻译出来却感觉不对味. 主要是那个assigned, 有点纠结.
如果对于英语不懂的话,可以下载有道词典软件或者“有道词典在线翻译”,效果都是还不错的。
叶斌兵 2015-02-09
  • 打赏
  • 举报
回复
即便你检查了 scanf 的返回值,你仍要检查用户的输入,检查用户的输入才是重点! 比如: char name[64]; char password[64]; memset(name, '\0', 64); memset(password, '\0', 64); scanf("%s%s", name, password); if( fcheck(name, password) == true) flogin(); else ferror(); 我的微博 http://www.7788tools.com 欢迎交流指正。
jialike2012 2015-01-29
  • 打赏
  • 举报
回复
老师这句话是箴言
xiaopao319 2015-01-27
  • 打赏
  • 举报
回复
我同意 我接分
greex 2015-01-13
  • 打赏
  • 举报
回复
必须的。所有有返回值的都必须判断。
Z_墨脱 2014-10-22
  • 打赏
  • 举报
回复
菜鸟从来没检查过
赵4老师 2014-05-26
  • 打赏
  • 举报
回复
引用 80 楼 jehovahs 的回复:
c语言还能这么牛!话说格式化控制输出的里面的^是干嘛的(我看完了所有的评论……)
To read strings not delimited by space characters, a set of characters in brackets ([ ]) can be substituted for the s (string) type character. The corresponding input field is read up to the first character that does not appear in the bracketed character set. If the first character in the set is a caret (^), the effect is reversed: The input field is read up to the first character that does appear in the rest of the character set.
jehovahs 2014-05-24
  • 打赏
  • 举报
回复
c语言还能这么牛!话说格式化控制输出的里面的^是干嘛的(我看完了所有的评论……)
evilshot 2014-03-28
  • 打赏
  • 举报
回复
灰常同意 Both scanf and wscanf return the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end-of-file character or the end-of-string character is encountered in the first attempt to read a character. the return value does not include fields that were read but not assigned. i couldn't really understand the meaning ;
OO_is_just_P 2014-03-23
  • 打赏
  • 举报
回复
有时候对这些检查是挺烦人的,但是不检查会要命的。 比如web开发中对post,get数据的检查,真是什么情况都可能发生,不做严格检查基本能5秒钟爆掉。有时候前端js检查了,只是为了增强客户体验而已。http随便post的,+-*、()=,全部post一遍,想起来头大。
赵4老师 2014-03-19
  • 打赏
  • 举报
回复
引用 76 楼 luyou1111 的回复:
同意接分
你来太晚了可惜。
天涯不语海角 2014-03-19
  • 打赏
  • 举报
回复
同意接分
耶鲁於 2014-01-16
  • 打赏
  • 举报
回复
引用 70 楼 easy_fefrry 的回复:
[quote=引用 69 楼 lin5161678 的回复:] [quote=引用 68 楼 easy_fefrry 的回复:] 如果不初始化, 你早请的内存中,可能有其它数据,包括乱码什么的。 哪有清0来的干净,用的放心呢! 我说的是可能!
不用可能 就算 全部都是垃圾数据又如何 直接覆盖使用那些有效数据就行了 不必在意那些所谓的乱码其他数据 [/quote] 的确可以覆盖的,虽然我无法很好的解释 。但我得到的建议是,但是我们公司的前辈是这样跟我说的。 也请知道的人,能够详说原理。好学习下![/quote] 加入这个函数没按照你的预想读取相应数目相应格式的数据,那你可不就把乱码当数据用了嘛
阿桑- 2014-01-01
  • 打赏
  • 举报
回复
同意!!!!
威尼斯妖孽 2013-12-09
  • 打赏
  • 举报
回复
同意~~~赞一个
jmuguy 2013-12-03
  • 打赏
  • 举报
回复
必须同意啊。举双脚同意
MEH-hz 2013-08-23
  • 打赏
  • 举报
回复
呵呵,表示同意
easy_fefrry 2013-07-09
  • 打赏
  • 举报
回复
引用 69 楼 lin5161678 的回复:
[quote=引用 68 楼 easy_fefrry 的回复:] 如果不初始化, 你早请的内存中,可能有其它数据,包括乱码什么的。 哪有清0来的干净,用的放心呢! 我说的是可能!
不用可能 就算 全部都是垃圾数据又如何 直接覆盖使用那些有效数据就行了 不必在意那些所谓的乱码其他数据 [/quote] 的确可以覆盖的,虽然我无法很好的解释 。但我得到的建议是,但是我们公司的前辈是这样跟我说的。 也请知道的人,能够详说原理。好学习下!
lin5161678 2013-07-08
  • 打赏
  • 举报
回复
引用 68 楼 easy_fefrry 的回复:
如果不初始化, 你早请的内存中,可能有其它数据,包括乱码什么的。 哪有清0来的干净,用的放心呢! 我说的是可能!
不用可能 就算 全部都是垃圾数据又如何 直接覆盖使用那些有效数据就行了 不必在意那些所谓的乱码其他数据
easy_fefrry 2013-07-05
  • 打赏
  • 举报
回复
引用 67 楼 lin5161678 的回复:
[quote=引用 65 楼 easy_fefrry 的回复:] 个人感觉有必要性,申请的内存最好初始为0啊!
在这里不初始化也不会有问题 那个memset 完全的多余的[/quote] 如果不初始化, 你早请的内存中,可能有其它数据,包括乱码什么的。 哪有清0来的干净,用的放心呢! 我说的是可能!
加载更多回复(67)

15,447

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧