Guardian C Library Calls Reference Manual
Reference to Library Calls
Guardian TNS C Library Calls Reference Manual—128833 3-57
fread
fread
The fread function reads data blocks from a file opened for ANSI I/O and then stores the
data blocks in an array.
dest_ptr
points to the array where fread stores the input blocks.
block_size
specifies the size in bytes of the blocks.
block_count
specifies the number of blocks to read.
stream
denotes a file opened for ANSI I/O.
Return Value
is the number of blocks read if the operation is successful; otherwise, fread returns
the value zero. If the value returned is less than you expected, use the ferror and feof
functions to determine the cause.
Example
This example reads 100 blocks of data from the file $a.b.c and writes them to the array
of structures named customer:
#include <stdioh>
FILE *fp;
struct snam_tag
{
char last[20];
char first[10];
char middle;
};
struct snam_tag customer[100];
fp = fopen("$a.b.c", "r");
/* ... */
fread((void *) customer, sizeof(struct snam_tag), 100, fp);
Note that the sizeof operator in the call to fread determines the size of the blocks.
#include <stdioh>
size_t fread(void *dest_ptr, size_t block_size,
size_t block_count, FILE *stream);