fread
Reads data from a stream
#include <stdio.h> size_t fread ( void *buf, size_t elsize, size_t nelem, FILE *fp);
The fread function returns the number of complete elements successfully read. This value can be less than the requested number of elements.
Call feof and ferror to determine whether the end of the file was encountered, or if an input/output error has occurred. If an error occurs, errno is set.
This function also works on the DOS partition.
The fread function reads nelem elements of elsize bytes each from the file specified by fp.
The following example reads a simple student record containing binary data. The student record is described by the struct student_data declaration.
#include <stdio.h> struct student_data { int student_id; unsigned char marks [10]; }; int read_data (FILE *fp, struct student_data *p) { return (fread (p, sizeof (*p), 1, fp) ); }