Q: Write down a C Program to Search Multiple Records of Given Name in Binary File.
As we have seen earlier a simple version of this program to search the first record with given name in a binary file. This program will show all such records having the given name of student in a binary file.
Since, there can be many students of the same name in a class or college.
The Main Logic Behind C Program to Search Multiple Records
As you can see that we have used a while loop to read records from a binary file. We used a break statement to terminate the while loop when a record is found with given name.
Now in finding multiple records we must search in all records. Therefore, we will remove break statement. Similarly, we have used a flag variable called “found”. We set this variable to 1 if a record is found. We can modify our C code to “found++;” instead of “found=1”. So that it can show the exact number of records found according to the given criteria.
The Source Code for Searching Multiple Records with given criteria
1,558 total views, 6 views today