HP C/iX Library Reference Manual (30026-90004)

Chapter 5 169
HP C/iX Library Function Descriptions
fread
fread
Reads data items from an open stream.
Syntax
#include <stdio.h>
size_t fread (void *
fileptr
, size_t
size
, size_t
nitems
,
FILE *
stream
);
Parameters
fileptr
A pointer to a buffer to hold the data. The type of the buffer is determined
by the type of the data being read.
size
The size of each data item, in bytes.
nitems
The number of data items to read.
stream
A pointer to an open stream.
Return Values
>0 The number of items actually read.
0 Either EOF was detected or an error occurred.
Description
The fread function reads
nitems
times
size
number of bytes into the buffer pointed to by
the
fileptr
argument. The bytes are read from the stream pointed to by the
stream
argument.
This function returns the number of items actually read. This may be less than the
number of requested items if an error occurs or an end of file is encountered.
NOTE
You must use special care when using fread() to access ASCII files from the
MPE/iX file system. These files are record-oriented text streams. The fread
function returns a new line character, \n, whenever it reaches an end of
record. You must take the \n character into account when reading, writing, or
repositioning within an MPE/iX fixed length ASCII file.
Binary MPE files behave differently from ASCII MPE files. See chapter 2,
"HP C/iX Library Input and Output," for more information.
Example
The following program keeps track of employee data. Each employee is described in a
single structure.