Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct atleta *linkAtleta, Atleta_t;
  5.  
  6. struct atleta
  7. {
  8.     char codice[5+1];
  9.     char *nome;
  10.     char *cognome;
  11.     char *categoria;
  12.     char data [10+1];
  13.     int ore;
  14.     linkAtleta next;
  15. };
  16.  
  17. typedef struct
  18. {
  19.     int nAtleti;
  20.     linkAtleta head;
  21.     linkAtleta tail;
  22. }tabAtleti;
  23.  
  24. typedef struct
  25. {
  26.     char *nome_es;
  27.     char *categoria_es;
  28.     char *tipologia_es;
  29. }esercizi;
  30.  
  31. typedef struct Piano_es *linkPiano, piano_t;
  32. struct Piano_es
  33. {
  34.     esercizi *es;
  35.     int set;
  36.     int rip;
  37.     linkPiano next;
  38. };
  39.  
  40. typedef struct
  41. {
  42.     esercizi *vettEsercizi;
  43.     int nEsercizi;
  44. }tabEsercizi;
  45.  
  46. void InserzioneTail(linkAtleta *hp, linkAtleta *tp);
  47. int main()
  48. {
  49.     FILE *fp;
  50.     Atleta_t *s_atleta;
  51.     esercizi *s_esercizi;
  52.  
  53.     struct node_es *eserPiano_t;
  54.     int N, i,numero, numero2, l_nome, l_cognome, l_categoria, comando, continua, l_esercizi;
  55.     char buf[25+1], nomefile[5+1];
  56.     linkAtleta head=NULL, tail=NULL, x;
  57.         fp=fopen("atleti.txt", "r");
  58.  
  59.     if (fp==NULL)
  60.     {
  61.         printf("errore apertura file\n");
  62.         return -1;
  63.     }
  64.     fscanf(fp, "%d", &N);
  65.     s_atleta=malloc(N*sizeof(Atleta_t));
  66.     for (i=0; i<N; i++)
  67.     {
  68.  
  69.         fscanf(fp, "%s", s_atleta->codice);
  70.  
  71.         fscanf(fp, "%s", buf);
  72.         l_nome=strlen(buf);
  73.         s_atleta->nome=(char*)malloc((l_nome+1)*sizeof(char));
  74.         strcpy(s_atleta->nome, buf);
  75.  
  76.         fscanf(fp, "%s", buf);
  77.         l_cognome=strlen(buf);
  78.         s_atleta->cognome=malloc((l_cognome+1)*sizeof(char));
  79.         strcpy(s_atleta->cognome, buf);
  80.  
  81.         fscanf(fp, "%s", buf);
  82.         l_categoria=strlen(buf);
  83.         s_atleta->categoria=malloc((l_categoria+1)*sizeof(char));
  84.         strcpy(s_atleta->categoria, buf);
  85.  
  86.         fscanf(fp, "%s", s_atleta->data);
  87.  
  88.         fscanf(fp, "%d", &s_atleta->ore);
  89.         InserzioneTail(&head, &tail);
  90.     }
  91.     for (x=head; x!=NULL; x=x->next)
  92.                 printf("%s %s %s %s %s %d\n", x->codice, x->nome, x->cognome,x->categoria, x->data , x->ore);
  93.     fclose(fp);
  94.     fp=fopen("esercizi.txt", "r");
  95.     fscanf(fp, "%d", &N);
  96.     s_esercizi=malloc(N*sizeof(esercizi));
  97.     for (i=0; i<N; i++)
  98.     {
  99.         fscanf(fp, "%s", buf);
  100.         l_esercizi=strlen(buf);
  101.         s_esercizi[i].nome_es=malloc((l_esercizi+1)*sizeof(char));
  102.          //ALTRIMENTI NON HO SPAZIO PER IL TAPPO, STRLEN NON LO CONTA
  103.          strcpy(s_esercizi[i].nome_es, buf);
  104.  
  105.         fscanf(fp, "%s", buf);
  106.         l_esercizi=strlen(buf);
  107.         s_esercizi[i].categoria_es=malloc((l_esercizi+1)*sizeof(char));
  108.         strcpy(s_esercizi[i].categoria_es, buf);
  109.  
  110.         fscanf(fp, "%s", buf);
  111.         l_esercizi=strlen(buf);
  112.         s_esercizi[i].tipologia_es=malloc((l_esercizi+1)*sizeof(char));
  113.         strcpy(s_esercizi[i].tipologia_es, buf);
  114.     }
  115.     fclose(fp);
  116.     printf("\n\n\n");
  117.     for (i=0; i<N; i++)
  118.         printf("%s %s %s\n", s_esercizi[i].nome_es, s_esercizi[i].categoria_es, s_esercizi[i].tipologia_es);
  119.  
  120.    //ricorda di non dover allocare memoria per la struct perchè è già salvato tutto
  121.  
  122.     return 0;
  123. }
  124. void InserzioneTail(linkAtleta *hp, linkAtleta *tp)
  125. {
  126.     Atleta_t *t;
  127.     t=malloc(sizeof *t);
  128.     if(*hp==NULL)
  129.         *hp=*tp=t;
  130.     else
  131.     {
  132.         (*tp)->next=t;
  133.         *tp=(*tp)->next;
  134.         (*tp)->next=NULL;
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement