[prev] [index] [next]

The fread function (cont)

Examples (read in data written above):

FILE *inf;
int array[50], n;
struct { float x; float y; } point;

inf = fopen("myDataFile","r");

// ... read array from file
if (fread(array, sizeof(int), 50, outf) != 50)
	fprintf(stderr, "Can't read array\n");

// ... read struct from file
if (fread(point, sizeof(point), 1, outf) != 1)
	fprintf(stderr, "Can't read struct\n");

For a more extensive example:
testfread.c