Accessing structure's variable in C++? -


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 way want search app"         <<"\n(1) search app name"         <<"\n(2) search developer name"         <<"\n(3) search type"         <<"\n(4) return previous menu\n";     cin>>choice;     cin.ignore();     switch(choice)     {         case 1:             dhome();             cout<<"\n\nenter app's name: ";             search_specific(a,"name");             //similar cases passing developer , 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 found , details 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 return previous menu";             getch();             return;         }         if(flag==0)         {             cout<<"\nthe app not found";             cout<<"\n\npress enter return previous menu";             getch();             return;         }      } 

now problem can't use a[i].choice because compiler tries find 'choice' in structure app. want refer value i.e name, developer or type. how can accomplish this?

you have formulate switch statement, reading desired member of value of type app following.

int choice; // read choice somewhere switch(choice) {     case 0:         // a[i].id         break;     case 1:         // a[i].name         break;     default;         break; } 

the members of struct cannot accessed index-wise.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -