struct app
{ int id;
char name[20];
char developer[20];
char type[20];
int date_uploaded [3];
};
.
.
.
void search(app a[2])
{
int choice;
char t_check[20];
Dhome();
cout<<"\n\nSelect the way you want to search for an app"
<<"\n(1) To search by app name"
<<"\n(2) To search by developer name"
<<"\n(3) To search by type"
<<"\n(4) To return to previous menu\n";
cin>>choice;
cin.ignore();
switch(choice)
{
case 1:
Dhome();
cout<<"\n\nEnter the app's name: ";
search_specific(a,"name");
//Similar cases for passing developer and type
}
}
void search_specific(app a[2], char choice[10])
{ int i, flag=0;
char t_check[20], s_type[5];
gets(t_check);
for(i=0; i<2; i++)
{
if(strcmp(t_check, a[i].choice)==0)
{
flag=1;
break;
}
}
if(flag==1)
{
cout<<"\nThe app was found and its details are as below"
<<"\nApp ID: "<<a[i].id
<<"\nApp Name: "<<a[i].name
<<"\nDeveloper Name: "<<a[i].developer
<<"\nType: "<<a[i].type
<<"\nDate Uploaded: "<<a[i].date_uploaded[0]<<"/"<<a[i].date_uploaded[1]<<"/<<a[i].date_uploaded[2];
cout<<"\n\nPress enter to return to the previous menu";
getch();
return;
}
if(flag==0)
{
cout<<"\nThe app was not found";
cout<<"\n\nPress enter to return to the previous menu";
getch();
return;
}
}
Now the problem is that I can't use a[i].choice because the compiler tries to find 'choice' in the structure app. I want it to refer to its value i.e name, developer or type. How can I accomplish this?
appdoesn't have a member namedchoice.