fread(3) CLIX fread(3)
NAME
fread, fwrite - Binary input/output
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <stdio.h>
#include <sys/types.h>
int fread(
char *ptr ,
size_t size ,
int nitems; ,
FILE *stream );
int fwrite(
char *ptr ,
size_t size ,
int nitems ,
FILE *stream );
PARAMETERS
ptr Points to an array.
size Specifies the size of a datum in bytes.
nitems Specifies the number of items to be copied.
stream Specifies a file.
DESCRIPTION
The fread() function copies, into an array pointed to by ptr, nitems items
of data from the named input stream where an item of data is a sequence of
bytes (not necessarily terminated by a null byte) of length size. The
fread() function 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() function leaves the file pointer in stream, if
defined, pointing to the byte following the last byte read if there is
one. The fread() function does not change the contents of stream.
The fwrite() function appends at most nitems items of data from the array
pointed to by ptr to the named output stream. The fwrite() function stops
appending when it has appended nitems items of data or if an error
condition is encountered on stream. The fwrite() function does not change
2/94 - Intergraph Corporation 1
fread(3) CLIX fread(3)
the contents of the array pointed to by ptr.
The argument size is typically sizeof(*ptr) where the pseudo-function
sizeof() specifies the length of an item pointed to by ptr. If ptr points
to a data type other than char it should be cast into a pointer to char.
EXAMPLES
FILE *fp *fopen()
char buffer [80];
int nread;
fp=fopen("scratch","r");
nread=fread(buffer,sizeof(char),80,fp);
RETURN VALUES
The fread() and fwrite() functions return the number of items read or
written. If nitems is not positive, no characters are read or written and
0 is returned by both fread() and fwrite().
RELATED INFORMATION
Functions: read(2), write(2), fopen(3), getc(3), gets(3), printf(3),
putc(3), puts(3), scanf(3), stdio(3)
2 Intergraph Corporation - 2/94