fread, fwrite
Purpose
Performs binary input/output.
Library
Standard I/O Library (libc.a)
Syntax
#include <stdio.h>
int fread ((char *) ptr, sizeof (*ptr), nitems, stream)
int nitems;
FILE *stream;
int fwrite ((char *) ptr, sizeof (*ptr), nitems, stream)
int size, nitems;
FILE *stream;
Description
The fread subroutine copies nitems items of data from the
input stream into an array beginning at the location
pointed to by the ptr parameter. Each data item has the
type *ptr.
The fread subroutine stops copying bytes if an end-of-
file or error condition is encountered while reading from
the input specified by the stream parameter, or when the
number of data items specified by the nitems parameter
have been copied. fread leaves the file pointer of
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 nitems items of data of the
type *ptr from the array pointed to by the ptr parameter
to the output stream.
The fwrite subroutine stops writing bytes if an error
condition is encountered on stream, or when the number of
items of data specified by the nitems parameter have been
written. The fwrite subroutine does not change the con-
tents of the array pointed to by the ptr parameter.
Return Value
The fread and fwrite subroutines return the number of
items actually read or written. If the nitems parameter
is negative or 0, no characters are read or written, and
a value of 0 is returned.
Related Information
In this book: "read, readx," "write, writex," "fopen,
freopen, fdopen," "getc, fgetc, getchar, getw," "gets,
fgets," "printf, fprintf, sprintf, NLprintf, NLfprintf,
NLsprintf," "putc, putchar, fputc, putw," "puts, fputs,"
"scanf, fscanf, sscanf, NLscanf, NLfscanf, NLsscanf," and
"standard i/o library."