C Program to Display Records From Binary File
“Read Records From Binary File” in C Programming is the program we will write today. We have already written a C program to Write Records in a Binary File. We have learned some basic standard library function used in C File programming.
- fopen() to open a file.
- fclose() to close a file
- fread() to read records one by one from a binary file. etc.
Syntax and use of fread() library function for files
Similarly, a standard library function in C programming language is known as fread() function. fread() has parameters similar to fwrite function. For example
fread ( &srecord, sizeof(srecord), 1, fp);
fread() function reads one record at a time, so we will put this function in a while loop. This while loop will continue to read one record at a time as long as fread() function is able to read a record. Therefore, This file reading while loop will break when end of file will be reached.
How many Records to Read and Display?
Since we have entered only two records in C File Program to write records in binary file. Therefore, these two records will be displayed on screen.
We may view the output screen of C program to write records in binary file. This confirms that we have inserted only two records in student binary file. We added these records when we executed a File Program to write records in a binary file. We used fwrite() function to write records in a binary file.
Source code of c program to read and show all records from a binary file.
3,557 total views, 18 views today