What is “short item count” in fread()?

心不动则不痛 提交于 2019-12-18 15:54:32

问题


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.


回答1:


If you want 4, and you have 3, then you're short 1.




回答2:


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.



来源:https://stackoverflow.com/questions/6338898/what-is-short-item-count-in-fread

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!