Everything

fread


Inputs data from a stream input/output file to the specified storage area.

[Format]

#include <stdio.h>

size_t fread (void *ptr, size_t size, size_t n, FILE *fp);

[Parameters]

ptr Pointer to storage area to which data is input

size Number of bytes in one member

n Number of members to be input

fp File pointer

[Return values]

When size or n is 0: 0

When size and n are both nonzero: Number of successfully input members

[Remarks]

The fread function inputs n members whose size is specified by size, from the stream input/output file indicated by file pointer fp, into the storage area pointed to by ptr. The file position indicator for the file is advanced by the number of bytes input.

The fread function returns the number of members successfully input, which is normally the same as the value of n. However, at end-of-file or when an error occurs, the number of members successfully input so far is returned, and then the return value will be less than n. The ferror and feof functions should be used to distinguish between end-of-file and error occurrence.

When the value of size or n is zero, zero is returned as the return value and the contents of the storage area pointed to by ptr do not change. When an error occurs or when only a part of the members can be input, the file position indicator is not guaranteed.