Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct stella *star;
- typedef struct pianeta *pl;
- typedef struct satellite *sat;
- typedef struct stella{
- char nome[25];
- star next;
- pl succ;
- } stella;
- typedef struct pianeta{
- char nome[25];
- pl next;
- sat succ;
- } pianeta;
- typedef struct satellite{
- char nome[25];
- sat next;
- } satellite;
- sat insSatellite(sat Z,char A[])
- {
- satellite *n,*temp=Z;
- n=malloc(sizeof(satellite));
- if(n==NULL) return NULL;
- strcpy(n->nome,A);
- n->next=NULL;
- if(Z==NULL) return n;
- while(temp->next!=NULL) temp=temp->next;
- temp->next=n;
- return Z;
- }
- sat leggiSatellite(pl n)
- {
- char c[2],A[25];
- sat Z=NULL;
- while(1)
- {
- printf("\nInserisci il nome del satellite: ");
- scanf("%s",A);
- Z=insSatellite(Z,A);
- printf("\nInserire altri satelliti? (y/n): ");
- scanf("%s",c);
- if(c[0]=='n') break;
- }
- return Z;
- }
- pl insPianeta(pl P,char A[])
- {
- char c[2];
- pianeta *n,*temp=P;
- n=malloc(sizeof(pianeta));
- if(n==NULL) return NULL;
- strcpy(n->nome,A);
- n->next=NULL;
- printf("\nVuoi inserire satelliti per questo pianeta?: (y/n) ");
- scanf("%s",c);
- if(c[0]=='n') n->succ=NULL;
- else
- {
- n->succ=leggiSatellite(n);
- }
- if(P==NULL) return n;
- while(temp->next!=NULL) temp=temp->next;
- temp->next=n;
- return P;
- }
- pl leggiPianeta(star n)
- {
- char c[2],A[25];
- pl P=NULL;
- while(1)
- {
- printf("\nInserisci il nome del pianeta: ");
- scanf("%s",A);
- P=insPianeta(P,A);
- printf("\nInserire altri pianeti? (y/n): ");
- scanf("%s",c);
- if(c[0]=='n') break;
- }
- return P;
- }
- star leggiStella(star S)
- {
- char c[2];
- stella *n;
- n=malloc(sizeof(stella));
- if(n==NULL) return S;
- printf("\nInserisci il nome della stella: ");
- scanf("%s",n->nome);
- n->next=NULL;
- printf("\nVuoi inserire pianeti per questa stella? (y/n): ");
- scanf("%s",c); //getchar();
- if(c[0]=='n')
- {
- n->succ=NULL;
- return n;
- }
- n->succ=leggiPianeta(n);
- return n;
- }
- void stampaSistema(star S)
- {
- printf("\n\n");
- pl p;
- sat q;
- printf("%s\n",S->nome);
- p=S->succ;
- while(p!=NULL)
- {
- printf("\t%s\n",p->nome);
- q=p->succ;
- while(q!=NULL)
- {
- printf("\t\t%s\n",q->nome);
- q=q->next;
- }
- p=p->next;
- }
- }
- int main(void)
- {
- star S;
- S=leggiStella(S);
- stampaSistema(S);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment