Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct atleta *linkAtleta, Atleta_t;
- struct atleta
- {
- char codice[5+1];
- char *nome;
- char *cognome;
- char *categoria;
- char data [10+1];
- int ore;
- linkAtleta next;
- };
- typedef struct
- {
- int nAtleti;
- linkAtleta head;
- linkAtleta tail;
- }tabAtleti;
- typedef struct
- {
- char *nome_es;
- char *categoria_es;
- char *tipologia_es;
- }esercizi;
- typedef struct Piano_es *linkPiano, piano_t;
- struct Piano_es
- {
- esercizi *es;
- int set;
- int rip;
- linkPiano next;
- };
- typedef struct
- {
- esercizi *vettEsercizi;
- int nEsercizi;
- }tabEsercizi;
- void InserzioneTail(linkAtleta *hp, linkAtleta *tp);
- int main()
- {
- FILE *fp;
- Atleta_t *s_atleta;
- esercizi *s_esercizi;
- struct node_es *eserPiano_t;
- int N, i,numero, numero2, l_nome, l_cognome, l_categoria, comando, continua, l_esercizi;
- char buf[25+1], nomefile[5+1];
- linkAtleta head=NULL, tail=NULL, x;
- fp=fopen("atleti.txt", "r");
- if (fp==NULL)
- {
- printf("errore apertura file\n");
- return -1;
- }
- fscanf(fp, "%d", &N);
- s_atleta=malloc(N*sizeof(Atleta_t));
- for (i=0; i<N; i++)
- {
- fscanf(fp, "%s", s_atleta->codice);
- fscanf(fp, "%s", buf);
- l_nome=strlen(buf);
- s_atleta->nome=(char*)malloc((l_nome+1)*sizeof(char));
- strcpy(s_atleta->nome, buf);
- fscanf(fp, "%s", buf);
- l_cognome=strlen(buf);
- s_atleta->cognome=malloc((l_cognome+1)*sizeof(char));
- strcpy(s_atleta->cognome, buf);
- fscanf(fp, "%s", buf);
- l_categoria=strlen(buf);
- s_atleta->categoria=malloc((l_categoria+1)*sizeof(char));
- strcpy(s_atleta->categoria, buf);
- fscanf(fp, "%s", s_atleta->data);
- fscanf(fp, "%d", &s_atleta->ore);
- InserzioneTail(&head, &tail);
- }
- for (x=head; x!=NULL; x=x->next)
- printf("%s %s %s %s %s %d\n", x->codice, x->nome, x->cognome,x->categoria, x->data , x->ore);
- fclose(fp);
- fp=fopen("esercizi.txt", "r");
- fscanf(fp, "%d", &N);
- s_esercizi=malloc(N*sizeof(esercizi));
- for (i=0; i<N; i++)
- {
- fscanf(fp, "%s", buf);
- l_esercizi=strlen(buf);
- s_esercizi[i].nome_es=malloc((l_esercizi+1)*sizeof(char));
- //ALTRIMENTI NON HO SPAZIO PER IL TAPPO, STRLEN NON LO CONTA
- strcpy(s_esercizi[i].nome_es, buf);
- fscanf(fp, "%s", buf);
- l_esercizi=strlen(buf);
- s_esercizi[i].categoria_es=malloc((l_esercizi+1)*sizeof(char));
- strcpy(s_esercizi[i].categoria_es, buf);
- fscanf(fp, "%s", buf);
- l_esercizi=strlen(buf);
- s_esercizi[i].tipologia_es=malloc((l_esercizi+1)*sizeof(char));
- strcpy(s_esercizi[i].tipologia_es, buf);
- }
- fclose(fp);
- printf("\n\n\n");
- for (i=0; i<N; i++)
- printf("%s %s %s\n", s_esercizi[i].nome_es, s_esercizi[i].categoria_es, s_esercizi[i].tipologia_es);
- //ricorda di non dover allocare memoria per la struct perchè è già salvato tutto
- return 0;
- }
- void InserzioneTail(linkAtleta *hp, linkAtleta *tp)
- {
- Atleta_t *t;
- t=malloc(sizeof *t);
- if(*hp==NULL)
- *hp=*tp=t;
- else
- {
- (*tp)->next=t;
- *tp=(*tp)->next;
- (*tp)->next=NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement