fread(3s)
NAME
fread, fwrite − buffered binary input/output
SYNTAX
#include <stdio.h>
int fread(ptr, sizeof(*ptr), nitems, stream)
char *ptr;
int sizeof, nitems;
FILE *stream;
int fwrite(ptr, sizeof(*ptr), nitems, stream)
char *ptr;
int sizeof, nitems;
FILE *stream;
DESCRIPTION
The fread subroutine reads nitems of data of the type of *ptr from the named input stream into a block beginning at ptr. It returns the number of items actually read. The fread subroutine stops appending bytes if an end-of-file or error condition is encountered while reading stream, or if nitems items have been read. The fread subroutine leaves the file pointer in stream, if defined, pointing to the byte following the last byte read if there is one. The fread subroutine does not change the contents of stream.
The fwrite subroutine appends at most nitems of data of the type of *ptr beginning at ptr to the named output stream. It returns the number of items actually written. The fwrite subroutine tops appending when it has appended nitems items of data or if an error condition is encountered on stream. The fwrite subroutine does not change the contents of the array pointed to by ptr.
DIAGNOSTICS
Both fread and fwrite return the number of items read or written.
Both fread and fwrite return 0 upon end of file or error.
SEE ALSO
read(2), write(2), fopen(3s), getc(3s), gets(3s), printf(3s), putc(3s), puts(3s), scanf(3s)