Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include<string.h>
  4. #define MAXC 25
  5. typedef struct
  6. {
  7. char nome[MAXC+1];
  8. char cognome[MAXC+1];
  9. char data[11+1];
  10. char codice[5+1];
  11. char Categoria[MAXC+1];
  12. int ore;
  13. }atleta;
  14.  
  15. int leggi_file(int N,atleta**A);//voglio passare la struct come riferimento
  16. void Stampa(int N,atleta*A);
  17. void Ord_Codice(atleta*A,int N,int *tipo_ordinamento);
  18. void Data(atleta*A,int N,int *tipo_ordinameto);
  19. int ConfrontaDate(char Data1[],char Data2[]);
  20. int main()
  21. {
  22. int N,t_O,continua=0;//t_O il tipo di Ordinamento Ord_Codice=1;Ord_Dat=2;Ord_nom=3,Ord_com=4 no ordi 78
  23. atleta*ATLETI;
  24. N=leggi_file(N,&ATLETI);
  25. t_O=78;
  26. printf("--->%d<---\n",N);
  27. Stampa(N,ATLETI);
  28. printf("\n\n\n");
  29. Ord_Codice(ATLETI,N,&t_O);
  30. Stampa(N,ATLETI);
  31. Data(ATLETI,N,&t_O);
  32. printf("\n\n\n");
  33. Stampa(N,ATLETI);
  34.  
  35. while(!continua)
  36. {
  37.     printf("scelta");
  38.     scanf("%d",&continua);
  39. }
  40. return 0;
  41. }
  42.  
  43. int leggi_file(int N,atleta**A)
  44. {
  45.     int Num_atl=0,i,giorno,mese,anno;
  46.     char dataloc[11];
  47.     atleta*temp_atl;
  48.     FILE*in;
  49.     in=fopen("atleti.txt","r");
  50.     if(in==NULL) {printf("Problema file in ingresso "); exit(45);}//controllo aperturafile
  51.     fscanf(in,"%d",&Num_atl);
  52.     temp_atl=(atleta*)malloc(Num_atl*sizeof(atleta));
  53.     if(temp_atl==NULL) {printf("Problema Allocazione"); exit(7);}
  54. for(i=0;i<Num_atl;i++)
  55. {
  56.     fscanf(in,"%s %s %s %s %s %d",temp_atl[i].codice,temp_atl[i].nome,temp_atl[i].cognome,temp_atl[i].Categoria,dataloc,&temp_atl[i].ore);
  57.     sscanf(dataloc,"%d/%d/%d",&giorno,&mese,&anno);
  58.     sprintf(dataloc,"%d/%d/%d",anno,mese,giorno);
  59.     strcpy(temp_atl[i].data,dataloc);
  60. }
  61.  
  62. *A=temp_atl;
  63. return Num_atl;
  64. }
  65.  
  66. void Stampa(int N,atleta*A)
  67. {   int i;
  68.     for(i=0;i<N;i++)
  69.     {
  70.         printf("%s %s %s %s %s %d\n",A[i].codice,A[i].nome,A[i].cognome,A[i].Categoria,A[i].data,A[i].ore);
  71.     }
  72. }
  73.  
  74. void Ord_Codice(atleta*A,int N,int *tipo_ordinamento)
  75. {
  76. int i,j;
  77. atleta X;
  78. for(i=1;i<=N;i++)
  79. {
  80.     X=A[i];
  81.     j=i-1;
  82.     while(j>=0&& (strcmp(X.codice,A[j].codice))<0)
  83.     {
  84.         A[j+1]=A[j];
  85.         j--;
  86.     }
  87. A[j+1]=X;
  88. }
  89. *tipo_ordinamento=1;
  90. }
  91.  
  92.  
  93. void Data(atleta*A,int N,int *tipo_ordinameto)
  94. {
  95. int i,j;
  96. atleta X;
  97. for(i=1;i<=N;i++)
  98. {
  99.     X=A[i];
  100.     j=i-1;
  101.     while(j>=0&& (strcmp(X.data,A[j].data))<0 )
  102.     {
  103.         A[j+1]=A[j];
  104.         j--;
  105.     }
  106. A[j+1]=X;
  107. }
  108. *tipo_ordinameto=2;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement