Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

cc(1)

read(2)

write(2)

fopen(3S)

getc(3S)

gets(3S)

printf(3S)

putc(3S)

puts(3S)

scanf(3S)

stdio(3S)

FREAD(3S)                            SysV                            FREAD(3S)



NAME
     fread, fwrite - binary input/output

SYNOPSIS
     #include <stdio.h>

     size_t fread(ptr, size, nmemb, stream)
     void *ptr;
     size_t size;
     size_t nmemb;
     FILE *stream;

     size_t fwrite(ptr, size, nmemb, stream)
     const void *ptr;
     size_t size;
     size_t nmemb;
     FILE *stream;

DESCRIPTION
     The fread function reads, into the array pointed to by ptr, up to nmemb
     elements whose size is specified by size, from the stream pointed to by
     stream.  The file position indicator for the stream (if defined) is
     advanced by the number of characters successfully read.  If an error
     occurs, the resulting value of the file position indicator for the stream
     is indeterminate.  If a partial element is read, its value is
     indeterminate.

     If stream is stdin or is unbuffered or line-buffered, then all active
     line-buffered output streams are flushed before any call to read(2) to
     satisfy the fread.

     fread returns the number of elements successfully read, which may be less
     than nmemb if a read error or EOF is encountered.  If size or nmemb is
     zero, fread returns zero and the contents of the array and the state of
     the stream remain unchanged.

     The fwrite function writes, from the array pointed to by ptr, up to nmemb
     elements whose size is specified by size, to the stream pointed to by
     stream.  The file position indicator for the stream (if defined) is
     advanced by the number of characters successfully written.  If an error
     occurs, the resulting value of the file position indicator for the stream
     is indeterminate.

     fwrite returns the number of items actually written, which will be less
     than nmemb only if a write error is encountered.

NOTES
     To be compatible with common C usage, make fread and fwrite return an int
     by compiling your program with the

          -A nansi

     option (see cc(1)) and inserting the directive

          #define _CLASSIC_TYPES

     before any

          #include

     directives.
SEE ALSO
     cc(1), read(2), write(2), fopen(3S), getc(3S), gets(3S), printf(3S),
     putc(3S), puts(3S), scanf(3S), stdio(3S).

DIAGNOSTICS
     fread and fwrite return the number of items read or written.  If nitems
     is non-positive, no characters are read or written and 0 is returned by
     both fread and fwrite.  Zero is returned on EOF or error.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026