C Language: fread function(Read Block from File)

In the C Programming Language, the fread function reads nmemb elements (each element is the number of bytes indicated by size) from the stream pointed to by stream and stores them in ptr.

Syntax

The syntax for the fread function in the C Language is:




size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);



Parameters or Arguments

ptr

The array where the elements will be stored.

size

The size of each element in bytes.

nmemb

The number of elements to read.

stream

The stream to read.

Returns

The fread function returns the number of elements read. The fread function will return zero if nmemb is zero or size is zero.

Required Header

In the C Language, the required header for the fread function is:




#include <stdio.h>



Applies To

In the C Language, the fread function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions





Instagram