Guest User

Untitled

a guest
Oct 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. struct comp ***ccompx(const char name[])
  2. {
  3.     struct comp **pv = (struct comp**) malloc(sizeof(struct comp*));
  4.     if(!pv)
  5.     {
  6.         puts("\nRicerca interrotta");
  7.     }
  8.     pv[0] = comps;
  9.     struct comp ***point;
  10.     struct comp *p = (struct comp*)malloc(sizeof(struct comp));
  11.     if(!p)
  12.     {
  13.         puts("\nRicerca interrotta");
  14.     }
  15.     int s = 1;
  16.     for(p = comps; p; p = p->n)
  17.     {
  18.         if(strstr(p->name, name))
  19.         {
  20.             pv = (struct comp **) realloc(pv, sizeof(struct comp*) * (s + 1));
  21.             if(!pv)
  22.             {
  23.                 puts("\nRicerca non completata");
  24.                 goto ret;
  25.             }
  26.             point = &pv;
  27.             (*point)[s] = p;
  28.             s++;
  29.         }
  30.     }
  31.     if(--s == 0)
  32.     {
  33.         free(point);
  34.         point = 0;
  35.         return point;
  36.     }
  37.     (*point)[0]->code = s;
  38. ret:
  39.     return point;
  40. }
  41.  
  42. int main()
  43. {
  44.     struct comp ***pv = ccompx(name);
  45.     if(pv)
  46.     {
  47.         int e = 0;
  48.         for(; (*pv)[0]->code > e++;)
  49.         {
  50.             printf("\nCodice del componente:           %d\n", (*pv)[e + 1]->code);
  51.             printf("Nome del componente:             %s\n", (*pv)[e + 1]->name);
  52.             printf("Descrizione del componente:      %s\n", (*pv)[e + 1]->des);
  53.             printf("Disponibilita' del componente:   %d\n\n", (*pv)[e + 1]->disp);
  54.         }
  55.     }
  56. }
Add Comment
Please, Sign In to add comment