Fread
Function Name: fread
Function: read data from a stream
Usage: int fread (void * PTR, int size, int nitems, file * stream );
Parameter: The address (PTR) used to receive data)
Size of a single element)
Number of elements (nitems)
Provides the data file pointer (Stream)
Returned value: number of successfully read Elements
Program Example:
# Include <string. h>
# Include <stdio. h>
Int main (void)
{
File * stream;
Char MSG [] = "this is a test ";
Char Buf [20];
If (Stream = fopen ("dummy. fil", "W + "))
= NULL)
{
Fprintf (stderr,
"Cannot open output file. \ n ");
Return 1;
}
/* Write some data to the file */
Fwrite (MSG, strlen (MSG) + 1, 1, stream );
/* Seek to the beginning of the file */
Fseek (stream, seek_set, 0 );
/* Read the data and display it */
Fread (BUF, 1, strlen (MSG) + 1, stream );
Printf ("% s \ n", Buf );
Fclose (Stream );
Return 0;
}