Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define MAXC 25+1
  6.  
  7. typedef struct  
  8. {
  9.    int ore;
  10.    char codice[6], *nome, *cognome, *categoria, nascita[11];
  11. }atleti;
  12.  
  13. typedef struct nodo *link;
  14.  
  15. typedef struct
  16. {
  17.     atleti atl;
  18.     link next;
  19. }Lista;
  20.  
  21. int leggiFile(link *head,link *tail);
  22. void inserimento_in_coda(link *head,link *tail,atleti val);
  23. link nuovo_nodo(atleti val,link next);
  24.  
  25. int main()
  26. {
  27.     int scelta, continua, N;
  28.     link  head,tail;
  29.  
  30.     N= leggiFile(&head,&tail);
  31.     return 0;
  32. }
  33.  
  34. int leggiFile(link *head,link *tail)
  35. {
  36.     int i,N;
  37.     char buf[MAXC];
  38.     FILE *atl;
  39.     atleti val;
  40.     link x;
  41.  
  42.     if((atl=fopen("atleti.txt", "r"))==NULL)
  43.     {
  44.         printf("ERRORE APERTURA FILE");
  45.         exit(EXIT_FAILURE);
  46.     }
  47.     fscanf(atl, "%d", &N);
  48.     for(i=0; i<N; i++)
  49.     {
  50.         fscanf(atl, "%s %s", val.codice, buf);
  51.         val.cognome= strdup(buf);
  52.         fscanf(atl, "%s", buf);
  53.         val.nome= strdup(buf);
  54.         fscanf(atl, "%s", buf);
  55.         val.categoria= strdup(buf);
  56.         fscanf(atl, "%s %d", val.nascita,&val.ore);
  57.     }
  58.     inserimento_in_coda(head,tail,val);
  59.     return N;
  60. }
  61. void inserimento_in_coda(link *head,link *tail,atleti val)
  62. {
  63.     if(*head==NULL) {
  64.         *head=*tail=nuovo_nodo(val,NULL);
  65.     } else {
  66.         (*tail)->next=nuovo_nodo(val,NULL);
  67.         *tail=(*tail)->next;
  68.     }
  69. }
  70. link nuovo_nodo(atleti val,link next)
  71. {
  72.     link x;
  73.  
  74.     x=(link)malloc(sizeof(Lista));
  75.     if(x!=NULL) {
  76.         x->atleti=val;
  77.         x->next=next;
  78.     }
  79.     return x;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement