Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 25
- typedef struct node *link;
- typedef struct Item{
- char codice[5];
- char*p_nome,*p_cognome,*p_categoria;
- struct{
- int a,m,g;
- } date;
- int ore;
- }item;
- struct node{
- item atleta;
- link next;
- };
- link newNode(item,link);
- link caricastrutture(link);
- void stampa(link);
- void stampa_a_video_anagrafica(link);
- void stampa_su_file_anagrafica(link);
- link aggiungi_al_fondo(link);
- link listSearch(link,char k[5]);
- link cancella_chiave(link h,char c[5]);
- void ricerca_codice(link);
- void aggiorna_ore(head);
- int main()
- {
- char c[5];
- link head=NULL;
- head=caricastrutture(head);
- printf("\n\n\n");
- stampa(head);
- //stampa_a_video_anagrafica(head);
- //stampa_su_file_anagrafica(head);
- //ricerca_codice(head);
- //aggiorna_ore(head);
- //head=aggiungi_al_fondo(head);
- printf("\ncodice dell'atleta da eliminare:");
- scanf("%s",c);
- printf("\n%s");
- head=cancella_chiave(head,c);
- //stampa(head);
- return 0;
- }
- link newNode(item atleta,link next) {
- link x = malloc(sizeof *x);
- if (x==NULL)
- return NULL;
- else {
- x->atleta = atleta;
- x->next = next;
- }
- return x;
- }
- link caricastrutture(link head){
- FILE *fp=fopen("atleti.txt","r");
- char nome[MAX],cognome[MAX],categorie[MAX];
- int n,i;
- item a;
- fscanf(fp,"%d",&n);
- printf("%d",n);
- for(i=0;i<n;i++){
- fscanf(fp,"%s %s %s %s %d/%d/%d %d",a.codice,nome,cognome,categorie,&a.date.g,&a.date.m,&a.date.a,&a.ore);
- printf("\n%s %s %s %s %d/%d/%d %d",a.codice,nome,cognome,categorie,a.date.g,a.date.m,a.date.a,a.ore);
- a.p_nome=strdup(nome);
- a.p_cognome=strdup(cognome);
- a.p_categoria=strdup(categorie);
- head=newNode(a,head);
- printf("\n%s %s %s %s %d/%d/%d %d",head->atleta.codice,head->atleta.p_nome,head->atleta.p_cognome,head->atleta.p_categoria,head->atleta.date.g,head->atleta.date.m,head->atleta.date.a,head->atleta.ore);
- // free(a.p_nome);
- //free(a.p_cognome);
- //free(a.p_categoria);
- printf("\n");
- }
- //*V=a;
- return head;
- }
- void stampa(link head){
- link x;
- for (x=head; x!=NULL; x=x->next){
- printf("\n%s %s %s %s %d/%d/%d %d",x->atleta.codice,x->atleta.p_nome,x->atleta.p_cognome,x->atleta.p_categoria,x->atleta.date.g,x->atleta.date.m,x->atleta.date.a,x->atleta.ore);
- }
- }
- void stampa_a_video_anagrafica(link head){
- link x;
- for (x=head; x!=NULL; x=x->next){
- printf("\n%s %s %d/%d/%d",x->atleta.p_nome,x->atleta.p_cognome,x->atleta.date.g,x->atleta.date.m,x->atleta.date.a);
- }
- }
- void stampa_su_file_anagrafica(link head){
- FILE *out=fopen("out.txt","w");
- link x;
- for (x=head; x!=NULL; x=x->next){
- fprintf(out,"%s %s %d/%d/%d\n",x->atleta.p_nome,x->atleta.p_cognome,x->atleta.date.g,x->atleta.date.m,x->atleta.date.a);
- }
- }
- link listSearch(link h,char k[5]) {
- link x;
- for (x=h; x!=NULL; x=x->next){
- if (strcmp(k,x->atleta.codice)==0){
- printf("trovato---->%s",x->atleta.p_nome);
- return x;
- }
- }
- return NULL;
- }
- void ricerca_codice(link head){
- link x;
- char cod[5];
- printf("\nscrivere codice da ricercare:");
- scanf("%s",cod);
- printf("%s",cod);
- x=listSearch(head,cod);
- printf("%s %s",x->atleta.p_nome,x->atleta.p_cognome);
- }
- void aggiorna_ore(link head){
- link x;
- printf("a chi vuoi aggiornare le ore:");
- char cod[5];
- scanf("%s",cod);
- x=listSearch(head,cod);
- scanf("%d",&(x->atleta.ore));
- printf("%s %s %s %s %d/%d/%d %d",x->atleta.codice,x->atleta.p_nome,x->atleta.p_cognome,x->atleta.p_categoria,x->atleta.date.g,x->atleta.date.m,x->atleta.date.a,x->atleta.ore);
- }
- link aggiungi_al_fondo(link head){
- char nome[MAX],cognome[MAX],categorie[MAX];
- item a;
- scanf("%s %s %s %s %d/%d/%d %d",a.codice,nome,cognome,categorie,&a.date.g,&a.date.m,&a.date.a,&a.ore);
- a.p_nome=strdup(nome);
- a.p_cognome=strdup(cognome);
- a.p_categoria=strdup(categorie);
- link x;
- if (head==NULL)
- return newNode(a, NULL);
- for (x=head; x->next!=NULL; x=x->next);
- x->next = newNode(a, NULL);
- return head;
- }
- link cancella_chiave(link h,char c[5]) {
- link x,p;
- if (h == NULL)
- return NULL;
- for (x=h, p=NULL; x!=NULL; p=x, x=x->next) {
- if (strcmp(c, x->atleta.codice)==0) {
- printf("trovato----->%s",x->atleta.codice);
- if (x==h) h=x->next;
- else p->next=x->next;
- free(x);
- break;
- }
- }
- return h;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement