Advertisement
Guest User

Untitled

a guest
Mar 11th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5.  
  6.     char Nome_sport[25];
  7.     int Ore;
  8.  
  9. }Sport;
  10.  
  11. typedef struct {
  12.  
  13.     int ID;
  14.     Sport *dati_sport;
  15.  
  16. }Info;
  17.  
  18. void Aggiungi(int,int,Info *);
  19.  
  20. int main()
  21. {
  22.  
  23. int scelta;
  24. int x = 1;
  25. Info informazioni[10]; // รจ fissato ( ho 10 classi )
  26. int scelta_id = 1;
  27. int i = 0;
  28.  
  29. do{
  30.  
  31. printf("\n[1] Aggiungi \t[0] Esci \n");
  32.  
  33. do{
  34.  
  35.      scanf("%d",&scelta);
  36.      if( scelta < 0 || scelta > 1 )
  37.                 {
  38.                     printf("\nScelta non valida...\n");
  39.                     printf("[1] Aggiungi  \t[0] Esci \n");
  40.                 }
  41.  }while(scelta < 0 || scelta > 1 );
  42.  
  43. switch(scelta){
  44.  
  45. case 1 :
  46.          Aggiungi(i,scelta_id,informazioni);
  47.          i++;
  48.          break;
  49.  
  50. case 0 :
  51.          x = 2;
  52.          break;
  53.  
  54. }
  55.  
  56. }while(x==1);
  57.  
  58.  
  59. printf("\nID: %d",informazioni[scelta_id].ID);
  60. printf("\nNome sport : %s",informazioni[scelta_id].dati_sport[0].Nome_sport);
  61. printf("\nNome sport : %s",informazioni[scelta_id].dati_sport[1].Nome_sport);
  62.  
  63. return 0;
  64. }
  65.  
  66.  
  67. void Aggiungi(int i,int scelta_id,Info *informazioni)
  68. {
  69.  
  70.  
  71.     Sport *dati = NULL;
  72.  
  73.     informazioni[scelta_id].ID = scelta_id;
  74.  
  75.     dati = (Sport *)malloc(1 * sizeof(Sport)); //allochiamo spazio per la struttura Sport
  76.     if(dati==NULL){
  77.  
  78.             printf("Errore");
  79.             exit(1);
  80.     }
  81.  
  82.     printf("\nInserisci i dati :");
  83.  
  84.                     printf("\nNome sport :");
  85.                     getchar();
  86.                     gets(dati[i].Nome_sport);
  87.  
  88.                     printf("\nInserisci le ore :");
  89.                     scanf("%d",&dati[i].Ore);
  90.  
  91.                     informazioni[scelta_id].dati_sport[i] = dati[i];
  92.  
  93.  
  94.    free(dati);
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement