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 node *link;
- typedef struct
- { char *nom;
- char *cognom;
- char codice[6+1];
- char *categoria;
- char data[11];
- int ore_all;
- }atleta;
- struct node
- {
- link next;
- atleta ATL;
- };
- link initList();
- atleta inAtleta(FILE *in);
- link NewNode(atleta bobbo);
- link listInTail(link h,int val);
- void stampaLista(link head);
- void InserisciATL(FILE *in, link nodo);
- void insTail(link *head,link x);
- void stampaAtleta(atleta x);
- int main()
- {
- int i=0,N_ATL=0;
- link head,q;
- head=initList();
- atleta tmp;
- FILE*in;
- in=fopen("atleti.txt","r");
- if(in==NULL) exit(50);
- fscanf(in,"%d",&N_ATL);
- for(i=0;i<N_ATL;i++)
- {
- tmp=inAtleta(in);
- q=NewNode(tmp);
- insTail(&head,q);
- }
- stampaLista(head);
- fclose(in);
- return 0;
- }
- link NewNode(atleta bobbo)
- {
- link x=malloc(1*sizeof(*x));
- if(x==NULL) return NULL;
- else
- {
- x->ATL=bobbo;
- x->next=NULL;
- }
- return x;
- }
- void stampaLista(link head){
- if(head==NULL) return;
- stampaAtleta(head->ATL);
- stampaLista(head->next);
- }
- void insTail(link *head,link x){
- link p;
- if((*head)==NULL){
- printf("La lista e' vuota\n");
- (*head)=x;
- }
- else{
- for(p=(*head);p->next!=NULL;p=p->next);
- p->next=x;
- x->next=NULL;
- }
- }
- link initList(){
- link tmp;
- tmp=NULL;
- return tmp;
- }
- void stampaAtleta(atleta x)
- {
- printf("%s %s %s %s %s %d\n",x.codice,x.nom,x.cognom,x.categoria,x.data,x.ore_all);
- return;
- }
- atleta inAtleta(FILE *in)
- {
- char str1[100+1],str2[100+1],str3[100+1];
- atleta x;
- fscanf(in,"%s %s %s %s %s %d",x.codice,str1,str2,str3,x.data,&x.ore_all);
- x.nom=strdup(str1);
- x.cognom=strdup(str2);
- x.categoria=strdup(str3);
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement