fread function
Prototype |
size_t fread (void * Buffer, size_t Size, size_t Count, FILE * Stream); |
Purpose | To read data from a file stream. |
Header File | #include <stdio.h> |
Parameters |
Buffer | Pointer to an area of variables where the data is to be placed |
Size | Size of each variable item |
Count | Number of variable items |
Stream | Pointer to an open FILE |
---|
|
---|
Return Value |
Count of items actually read.
|
Notes |
- The number of bytes read will be Size times the return value.
- If end of file is reached (or an error occurs) before Count items are read, the return
value (count of items actually read) will be less than the number requested.
- If a file is opened for update, both reads and writes are allowed; however,
they must be separated from each other by an intervening seek or rewind.
- The type size_t is defined in stdio.h.
|
Example |
#include
. . .
FILE * Temperatures;
int Temperature [24];
size_t Count;
int i;
. . .
Count = fread (Temperature, sizeof (int), (size_t) 24, Temperatures);
for (i = 0; i < (int) Count; ++ i) {
printf ("Temperature %i = %i.", i, Temperature [i]);
}
|
Related functions |
|