Advertisement
Guest User

Untitled

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