Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo 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>

 size_t     fread(buffer,size,count,stream);
 void       *buffer;                     Storage location for data
 size_t     size;                        Item size in bytes
 size_t     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 a file pointer is 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 '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 an existing file, read 128 characters
    from the file into a buffer, then print the contents of that buffer.

           #include <stdio.h>

           FILE *stream;
           char buffer[128];
           int x;

           main()
           {
               if ((stream = fopen("book.dat","r+")) != NULL) {
                   fread(buffer, sizeof(char), 128, stream);
                   for (x = 0; x < 128; x++)
                      printf("%c",buffer[x]);
               }
           }


See Also: fwrite() read()

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