0% found this document useful (0 votes)
386 views

File Structures VTU LAB MANUAL

The document describes a function called search() that searches a student record file for a student record matching a given registration number (rrn). It opens the file, reads each record into an array, and loops through the array comparing the rrn fields to the input rrn. If a match is found, it prints the matching record details and returns. If no match is found after searching all records, it prints that the record was not found.

Uploaded by

AdilHEngineer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
386 views

File Structures VTU LAB MANUAL

The document describes a function called search() that searches a student record file for a student record matching a given registration number (rrn). It opens the file, reads each record into an array, and loops through the array comparing the rrn fields to the input rrn. If a match is found, it prints the matching record details and returns. If no match is found after searching all records, it prints that the record was not found.

Uploaded by

AdilHEngineer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

void search()

{
char rrn[10],rrn1[10][15];
int i;
student std[100];
cout<<"\n enter the rrn to be searched";
cin>>rrn;
fstream file;
file.open("program_4.txt",ios::in);
if(!file)
{
cout<<"\n can not open the file in input mode";
//getch();
exit(0);
}
i=0;
printf("\n rrn\tname\tusn\tage\tsem\tbranch\n");
while(!file.eof())
{
file.getline(rrn1[i],4,'|');
file.getline(std[i].name,15,'|');
file.getline(std[i].usn,15,'|');
file.getline(std[i].age,5,'|');
file.getline(std[i].sem,5,'|');
file.getline(std[i].branch,15,'\n');
i++;
}
for(int j=0;j<i-1;j++)
{
if(strcmp(rrn,rrn1[j])==0)
{
printf("\n%s\t%s\t%s\t%s\t%s\t%s\n",
rrn,std[j].name,std[j].usn,std[j].age,
std[j].sem,std[j].branch);
printf("\n record found\n");
file.close();
return;
}
}
cout<<"\nrecord not found\n";
file.close();
return;
}
int main()
{
int choice;
//clrscr();
while(1)
{
cout<<"\n 0:exit";
cout<<"\n 1:insert";
cout<<"\n 2:search";
cout<<"\n 3:display";
cout<<"\n enter the choice=";
cin>>choice;
switch(choice)
{

case 1: writerecord();
break;
case 2: search();
break;
case 3: displayfile();
break;
case 0: exit(0);
default: cout<<"\n invalid option";
break;
}
}
return 0;
}

You might also like