开发者

What is "short item count" in fread()?

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜