jaysome schrieb:
On Sun, 24 Dec 2006 11:13:02 -0800, Keith Thompson <ks***@mib.org>
wrote:
>You can also use fgetc(); fread() is defined in terms of repeated
calls to fgetc().
I don't see anywhere in the standard where it says that fread() is
defined in terms of repeated calls to fgetc(). That would be very
inefficient on some implementations when reading a "large" amount of
bytes.
n1124.pdf, 7.19.8.1p2
The fread function reads, into the array pointed to by ptr, up to
nmemb elements whose size is specified by size, from the stream
pointed to by stream. For each object, size calls are made to the
fgetc function and the results stored, in the order read, in an
array of unsigned char exactly overlaying the object. The file
position indicator for the stream (if defined) is advanced by the
number of characters successfully read. If an error occurs, the
resulting value of the file position indicator for the stream is
indeterminate. If a partial element is read, its value is
indeterminate.
fread() just has to behave like repeated calls to fgetc(), but may be
implemented otherwise (as-if clause).