什么是“短项计数”?在 fread() 中?
当我“害怕”时,我得到了这个:
返回值
fread() 和 fwrite() 返回成功读取或写入的项目数(即,不是字符数)。如果出现错误 发生,或者结束 到达 of-file 时,返回值是短项计数(或零)。fread() 不区分文件结束和错误,调用者必须使用 feof(3) 和 Ferror(3) 来确定发生的是哪一个。
所以我的问题是如何理解“短项目计数”。请忍受我的英语。为什么这里涉及“short”类型?您能举例说明“短项计数”是什么样的吗?谢谢。
When I was 'man fread', I got this:
RETURN VALUE
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error
occurs, or the end-
of-file is reached, the return value is a short item count (or zero).fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred.
So my question is to how to understand "short item count". Please bear with my English. Why here involves type "short"? Can you someone give an example of what does "short item count" look like? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
fread 手册页中“短”的含义并不是指数据类型。
在这种情况下,“短”意味着“低于预期”。如果 fread() 期望读取 4 个对象,但只读取了 3 个,它将返回值 3。
我认为手册页应该重写为:
“如果发生错误,或到达文件末尾,则返回值是发生错误或 EOF 之前成功读取或写入的项目数。
The meaning of "short" in fread man page does not refer to a data type.
"Short" in this case means "less then expected". If fread() expected to read 4 objects, but only read 3, it will return the value 3.
I believe that the the man page should be re-written to say:
"If an error occurs, or the end-of-file is reached, the return value is the number of items successfully read or written up until the error or EOF occurred.
如果你想要 4,而你有 3,那么你就缺 1。
If you want 4, and you have 3, then you're short 1.