binary stream input/output

You're viewing an older version of this page (#3251). View the current version.

View versions (3)

NAME

<span class="Nm" id="fread">fread</span>, <span class="Nm" id="fwrite">fwrite</span>

INTERFACE

#include <stdio.h> size_t fread ( void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream ) size_t fwrite ( const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream )

DESCRIPTION

The function fread reads &#92;c nmemb objects, each &#92;c size bytes long, from the stream pointed to by &#92;c stream, storing them at the location given by &#92;c ptr. &#92;n &#92;n The function fwrite writes &#92;c nmemb objects, each &#92;c size bytes long, to the stream pointed to by &#92;c stream, obtaining them from the location given by &#92;c ptr.

RETURN VALUES

The functions fread and fwrite advance the file position indicator for the stream by the number of bytes read or written. They return the number of objects read or written. If an error occurs, or the end-of-file is reached, the return value is a short object count (or zero). &#92;n &#92;n The function fread does not distinguish between end-of-file and error, and callers must use reference:feof (3) and ferror (3) to determine which occurred. The function fwrite returns a value less than &#92;c nmemb only if a write error has occurred.

SEE ALSO

reference:read (2) , reference:write (2)

STANDARDS

The functions fread and fwrite conform to