关注
遇到这种C语言函数/系统调用/过程调用的问题的时候,就在shell里man一下,仔细读读Linux Mannual。 比如说这个问题,man 3 scanf 然后输入/return 然后就会看到这么一段话: On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure. The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set to indicate the error. 你就知道啊原来读到结尾或者read出错就会返回EOF。那么什么时候read会出错呢? 我们知道C语言中具体的错误类型通常由一个线程局部变量errno标识,manual里面也会对库函数可能引发的错误作阐述。 然后你可以看看下面的errno的描述: ERRORS EAGAIN The file descriptor underlying stream is marked nonblocking, and the read operation would block. EBADF The file descriptor underlying stream is invalid, or not open for reading. EILSEQ Input byte sequence does not form a valid character. EINTR The read operation was interrupted by a signal; see signal(7). EINVAL Not enough arguments; or format is NULL. ENOMEM Out of memory. ERANGE The result of an integer conversion would exceed the size that can be stored in the corresponding integer type. 你大概心里对哪些情况scanf会出错应该就有点想法了吧?
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
04-10 10:22
河南工业大学 软件测试 点赞 评论 收藏
分享
05-05 12:57
门头沟学院 前端工程师
记着呢:说的很对,已经工作近7年,就是觉得年轻的时候太多忧虑,没有好好玩一玩,虽然现在我也是很多忧心事,但是真的感觉年轻的时光才是最宝贵的,玩的开心,做自己喜欢的事,全力以赴,这才是应该做的 点赞 评论 收藏
分享
牛客热帖
更多
- 1... 毕业啦!我们要一起去广州打拼啦!2.8W
- 2... 毕业了,有些话只能藏在心里了2.4W
- 3... 2026春招到底卷成什么样了?填问卷说出真相,最高领200元现金红包2.1W
- 4... 字节 中国交易与广告 后端一面1.7W
- 5... 华为暑期实习1.2W
- 6... 从腾讯 字节到阿里 从前端到Agent 感谢一路走来的我自己😭1.0W
- 7... 别人:阿里 字节 腾讯9908
- 8... 211本,130投0面,agent应用开发,简历求助!8654
- 9... 大三下了 学校不放实习怎么办8515
- 10... 从阿里被裁到快手升P6,我花了四年7711
正在热议
更多
# 如果春招能重来,我会___ #
28600次浏览 281人参与
# 机械人还在等华为开奖吗? #
339043次浏览 1652人参与
# 联宝杯大学生创新大赛,你的技术值得产业级答案 #
50261次浏览 778人参与
# 这个offer值得去吗? #
30166次浏览 215人参与
# 华为池子有多大 #
177777次浏览 930人参与
# 你会因为行情,降低找工作标准吗? #
44009次浏览 319人参与
# 在爱玛,骑向未来 #
19742次浏览 388人参与
# 24秋招避雷总结 #
1019557次浏览 7097人参与
# 机械人,你的秋招第一份简历被谁挂了 #
268628次浏览 2450人参与
# 远程面试的尴尬瞬间 #
363673次浏览 2062人参与
# 大学最后一个寒假,我想…… #
103202次浏览 846人参与
# 机械求职避坑tips #
103594次浏览 589人参与
# 校招薪资来揭秘 #
960072次浏览 4060人参与
# 记录我的毕业季 #
4103次浏览 111人参与
# 26届春招投递记录 #
8495次浏览 71人参与
# 网易求职进展汇总 #
212991次浏览 1523人参与
# 刚入职就____,这样正常吗? #
148659次浏览 709人参与
# 选择和努力,哪个更重要? #
211667次浏览 1566人参与
# 去年你投递实习了吗? #
32798次浏览 339人参与
# 你被哪些公司挂了? #
194644次浏览 1056人参与
# 春招前还要继续实习吗? #
66845次浏览 330人参与
# 字节开奖 #
159030次浏览 780人参与
查看3道真题和解析