17/09/11 15:52
drewnik99
Ecco il codice:
La funzione main non riesce a leggere le strutture individuate dalla funzione compx:
L'istruzione restituisce errore. Qualche suggerimento?
struct comp { int code; char name[25]; char des[100]; int disp; struct comp *n; }; struct comp *comps = 0; int glob; struct comp ***ccompx(const char name[]) { struct comp **pv = (struct comp**) malloc(sizeof(struct comp*)); if(!pv) { puts("\nRicerca interrotta"); } struct comp ***point; struct comp *p = (struct comp*)malloc(sizeof(struct comp)); if(!p) { puts("\nRicerca interrotta"); } glob = 0; for(p = comps; p; p = p->n) { if(strstr(p->name, name)) { pv = (struct comp **) realloc(pv, sizeof(struct comp*) * (glob + 1)); if(!pv) { puts("\nRicerca non completata"); goto ret; } point = &pv; (*point)[glob] = p; glob++; } } ret: return point; } int main() { char name[25]; printf("Inserisci la chiave di ricerca: "); scanf("%s", &name); struct comp ***pv = ccompx(name); if (pv && *pv && (*pv)[0]) { int codep; puts("\n1 - Visualizzazione completa"); puts("2 - Tabella"); puts("3 - Torna al menu'"); printf("\nCome si intende visualizzare i componenti: "); fflush(stdin); scanf("%i", &codep); switch(codep) { case 1: for(int i = 0; glob > i++;) { printf("\nCodice del componente: %i\n", (*pv)[i]->code); printf("Nome del componente: %s\n", (*pv)[i]->name); printf("Descrizione del componente: %s\n", (*pv)[i]->des); printf("Disponibilita' del componente: %i\n\n", (*pv)[i]->disp); } break; case 2: printf("\nCODICE DISPONIBILITA' NOME\n\n"); for(int i = 0; glob > i++;) { printf("%6d%16d%-99s\n", (*pv)[i]->code, (*pv)[i]->disp, (*pv)[i]->name); } case 3: default: free(pv); return; } free(pv); } else { puts("\nNessun componente trovato"); } }
La funzione main non riesce a leggere le strutture individuate dalla funzione compx:
printf("\nCodice del componente: %i\n", (*pv)[i]->code);
L'istruzione restituisce errore. Qualche suggerimento?
Ultima modifica effettuata da drewnik99 18/09/11 9:34
aaa