关注
遇到这种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会出错应该就有点想法了吧?
查看原帖
点赞 评论
相关推荐
10-30 16:31
重庆大学 Java 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 2025年终总结 #
168952次浏览 2849人参与
# 找工作,行业重要还是岗位重要? #
84962次浏览 1681人参与
# 职场上哪些行为很加分? #
305968次浏览 3441人参与
# 大家每天通勤多久? #
68992次浏览 436人参与
# 你面试体验感最差/最好的公司 #
14647次浏览 238人参与
# 一人说一个提前实习的好处 #
9085次浏览 184人参与
# 今年你最想重开的一场面试是? #
3119次浏览 59人参与
# 秋招落幕,你是He or Be #
8984次浏览 188人参与
# 重来一次,你会对开始求职的自己说 #
5439次浏览 137人参与
# 实习没事做是福还是祸? #
14788次浏览 227人参与
# 团建是“福利”还是是 “渡劫” #
6464次浏览 143人参与
# 实习的内耗时刻 #
210396次浏览 1533人参与
# 你小心翼翼的闯过多大的祸? #
10494次浏览 150人参与
# 大厂VS公务员你怎么选 #
74118次浏览 680人参与
# 比亚迪工作体验 #
73971次浏览 280人参与
# 工作中听到最受打击的一句话 #
5264次浏览 94人参与
# 大家实习每天都在干啥 #
106331次浏览 575人参与
# 如何排解工作中的焦虑 #
247818次浏览 2285人参与
# 我的第一份实习怎么找的 #
208365次浏览 1824人参与
# 长城汽车工作体验 #
12922次浏览 16人参与
查看1道真题和解析