fread() - I/O Function
How is "fread()" used in C++?
is an I/O function which is used to read the
specified number of objects, of the "size" from a specified stream and places them in an array. This function returns the
actual number of items, if less numbers are shown then there might be an error or EOF has reached.
size_t fread( void *buf, size_t size,
size_t count, FILE * stream);
ptr = fopen("freadeg.txt", "r");
i = fread(str, 1,5,ptr);
str[i] = ' ';
printf("The characters read are::%s\n", str);
printf("Number of characters read:: %d\n\n", i);
The characters read are::01234
Number of characters read:: 5
In the above example the fread() is used to read first "5" character from a text file.