fread(), fwrite() - binary stream input/output
#include <stdio.h>
int fread (void *ptr, size_t size, size_t nmemb, FILE *stream)
int fwrite (const void *ptr, size_t size, size_t nmemb,
FILE *stream)
The function fread(3) reads nmemb objects, each size(1) bytes long, from the stream pointed to by stream, storing them at the location given by ptr.
The function fwrite(3) writes nmemb objects, each size bytes long, to the stream pointed to by stream, obtaining them from the location given by ptr. The functions fread(3) and fwrite(3) advance the file position indicator for the stream by the number of bytes read or written.
Fread(3) and fwrite(3) 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).
Because the function fread(3) does not distinguish between end-of-file and error, callers must use feof(3) and ferror(3) to determine which occurred.
The function fwrite(3) returns a value less than nmemb only if a write error has occurred.
Fread(3) can set errno to the following values:
Fwrite(3) can set errno to the following values:
read(2)
write(2)