


FREAD(3S)            STANDARD I/O FUNCTIONS             FREAD(3S)



NAME
     fread, fwrite - buffered binary input/output

SYNOPSIS
     #include <stdio.h>

     int fread (ptr, size, nitems, stream)
     char *ptr;
     int size;
     int nitems;
     FILE *stream;

     int fwrite (ptr, size, nitems, stream)
     char *ptr;
     int size;
     int nitems;
     FILE *stream;

DESCRIPTION
     fread() reads, into a block pointed to by _p_t_r, _n_i_t_e_m_s  items
     of data from the named input stream _s_t_r_e_a_m, where an item of
     data is a sequence of bytes (not necessarily terminated by a
     null  byte)  of length _s_i_z_e.  It returns the number of items
     actually read.  fread() stops reading if an  end-of-file  or
     error condition is encountered while reading from _s_t_r_e_a_m, or
     if _n_i_t_e_m_s items have been read.   fread()  leaves  the  file
     pointer  in _s_t_r_e_a_m, if defined, pointing to the byte follow-
     ing the last byte read if there is one.   fread()  does  not
     change the contents of the file referred to by _s_t_r_e_a_m .

     fwrite() writes at most _n_i_t_e_m_s items of data from the  block
     pointed  to  by  _p_t_r  to the named output stream _s_t_r_e_a_m.  It
     returns the number  of  items  actually  written.   fwrite()
     stops writing when it has written _n_i_t_e_m_s items of data or if
     an error condition is encountered on _s_t_r_e_a_m.  fwrite()  does
     not change the contents of the block pointed to by _p_t_r.

     If _s_i_z_e or _n_i_t_e_m_s is non-positive, no characters are read or
     written and 0 is returned by both fread() and fwrite().

SEE ALSO
     read(2V),   write(2V),   fopen(3V),   getc(3V),    gets(3S),
     putc(3S), puts(3S), printf(3V), scanf(3V)

DIAGNOSTICS
     fread() and fwrite() return 0 upon end of file or error.









Sun Release 4.1   Last change: 7 September 1988                 1



