C Program to Search a Record in Binary File C Programming

By | June 29, 2019

Q: Write a C program to Search a Record in Binary File in C Programming.

What is the input of Record Search C Program?

This C program will input a field to start a search with. For example, in a student binary file, we will input roll number of the student to start search in c file.

C Program to search a record in binary file

C Program to search a record in binary file

How To Search A Record In Binary File?

When we have a given roll number to start search with, we will open the binary file in read mode:

/*open binary file in read mode*/

If the file has been opened successfully, we will use a while loop to read file one record at a time until EOF is reached.

First of all we use fread() function to read first record. The roll number of currently read record is matched with given roll no. if both are matched, we display record.

Similarly, the program will read all recordsĀ  one by one and compare with given roll no. If no such record is in the binary file, we will display “Record Not Found Message”.

The source code of Record Search Program in Binary File using C Programming is:

/* Write a C program to input a Roll No then 
search the record of this student in a binary file

struct student
int rollno;
char name[30];

int main()
FILE *fptr;

int found=0, roll;

/*open binary file in read mode*/
printf("File could not open");

printf("\n Enter Roll No of Student to Search Record=");

	if(srecord.rollno == roll)
	printf("\nRecord of Student With RollNo %d is as follows:",roll);
	printf("\nRoll No:%d",srecord.rollno);
   printf("\n Record Not found in this file!");
return 0;

 3,384 total views,  2 views today

Leave a Reply

Your email address will not be published.