Name | Description | Notes | Source | Availability | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
fread() |
Input bytes | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 | |||
fwrite() |
Output bytes | (·) | <stdio.h> |
C89 | C90 | C95 | C99 | C11 |
<stdio.h>
provides two functions for writing and reading chunks of
bytes to and from
open streams.
#include <stdio.h>
size_t fread(void *ptr,
size_t chsz, size_t nch,
FILE *str);
size_t fwrite(const void *ptr,
size_t chsz, size_t nch,
FILE *str);
fread
reads
nch
chunks of chsz
bytes each from the stream str
, and writes them to the array of at least
nch
×chsz
bytes
starting at ptr
. Only whole chunks are
read, and the number of whole chunks read is returned.
fwrite
reads
nch
chunks of chsz
bytes each from the array of at least
nch
×chsz
bytes
starting at ptr
, and writes them to
the stream str
. Only whole chunks are
written, and the number of whole chunks written is
returned.
These functions stop on error or end-of-file, and so
feof
and ferror
should be called to test for these
conditions if the return value is less than nch
.