Cant Search 2 files together :(
I did this coding. This function will search through 2 files.
But when even I enter any number to search it goes to the previous menu.
Mainly I wanted this function to do is that if i search for a number, It should first search the first file, if found it will display the search and if not found it will search the second file.
and display the result.
Please check the code tell me where am i going wrong?
void R_search()
{
fstream file1;
fstream file2;
char *temp;
cout<<"Enter Phone";
gets(temp);
file1.open("person.txt",ios::app|ios::out);
if(!file1)
{
cout<<"\nError in opening the file PERSON ";
getch();
}
else
{
file1.read((char *)&person,sizeof(person));
while(!file1.eof())
{
int i=strcmp(person.retphone_person(),temp);
if(i==0)
{
person.display_person();
getch();
}
}
}
file2.open("busniess.txt",ios::app|ios::out);
if(!file2)
{
cout<<"\nError in opening the file BUSNIESS";
getch();
}
else
{
file2.read((char *)&busniess,sizeof(busniess));
while(!file2.eof())
{
int i=strcmp(busniess.retphone_busniess(),temp);
if(i==0)
{
busniess.display_busniess();
getch();
}
}
}
file1.close();
file2.close();
}