I am trying to understand how the fread()
function in <stdio.h>
works and I am confused about the return value of this function. In the man pages it says
RETURN VALUE
On success,fread()
andfwrite()
return the number of items read or written. This number equals the number of bytes transferred only when size is 1. If an error occurs, or the end of the 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 usefeof(3)
andferror(3)
to determine which occurred.
Could someone please explain to me what is meant by number of items read or written
in this context. Also can anyone provide me with some example return values and their meanings?