Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>fread() read unformatted data from stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fread()                  Read Unformatted Data from Stream

 #include   <stdio.h>

 int        fread(buffer,size,count,stream);
 char       *buffer;                     Storage location for data
 int        size;                        Item size in bytes
 int        count;                       Max number of items to read
 FILE       *stream;                     Pointer to file structure

    fread() reads a maximum of 'count' items of data, each of length
    'size' bytes, from the input 'stream' and stores them in 'buffer'.
    If there is a file pointer associated with 'stream', it is
    incremented by the number of bytes actually read.

    Returns:    The number of items actually read.  This number may be
                less than 'count' if an error occurs or end-of-file is
                reached before reaching 'count'.

      Notes:    If 'stream' was opened in text mode, the replacement of
                (CR-LF) with (LF) has no effect on the file pointer
                return value.

  -------------------------------- Example ---------------------------------

    The following statements open a file and read 128 characters from the
    stream.

         #include <stdio.h>

         FILE *stream;
         char buffer[128];

         main()
         {
             if ((stream = fopen("book.dat","r+")) != NULL) {
                 fread(buffer, sizeof(char), 128, stream);
             }
         }

See Also: fwrite() read()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson