fread() Function in C Programming

aimtocode

The fread() function

The fread() function is used to read bytes form the file.

Syntax

  fread( ptr, int size, int n, FILE *fp );
  • The fread() function takes four arguments.
  • ptr : ptr is the reference of an array or a structure where data will be stored after reading.
  • size : size is the total number of bytes to be read from file.
  • n : n is number of times a record will be read.
  • FILE* : FILE* is a file where the records will be read.

Example:



Output:

 Roll     Name       Marks
 1         Ashish      78.53
 2         Kaushal    72.65
 3         Vishwas    82.65
aimtocode