fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct Range
  6. {
  7. float rec_min;
  8. float rec_max;
  9. } range;
  10.  
  11. typedef struct Dati
  12. {
  13. char cognome[41];
  14. char nome[41];
  15. int podi;
  16. float record;
  17. int giorno;
  18. int mese;
  19. int anno;
  20. } dati;
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24. FILE *fa, *fp;
  25. range v[100];
  26. dati x;
  27. int i=0, j, podi_min=10000, podi_max=0, flag=0;
  28. int anno=0, mese=0, giorno=0;
  29.  
  30. if(argc!=2)
  31. {
  32. printf("Usage: %s filename\n", argv[0]);
  33. return -1;
  34. }
  35.  
  36. fp=fopen("filter.txt", "r");
  37.  
  38. if(fp==NULL)
  39. {
  40. printf("Errore nell'apertura del file filter.txt\n");
  41. return -2;
  42. }
  43.  
  44. while(fscanf(fp, "%f %*c %f", &v[i].rec_min, &v[i].rec_max)!= EOF)
  45. {
  46. i++;
  47. }
  48. fclose(fp);
  49.  
  50. fa=fopen(argv[1], "r");
  51.  
  52. if(fa==NULL)
  53. {
  54. printf("Errore nell'apertura del file %s", argv[1]);
  55. return -3;
  56. }
  57.  
  58. printf(" Nome Cognome\t Podi\tRecord\t Data\n");
  59.  
  60. while(fscanf(fa,"%s %s %d %f %d/%d/%d", x.nome, x.cognome, &x.podi, &x.record, &x.giorno, &x.mese, &x.anno)!=EOF)
  61. {
  62. for(j=0; j<i; j++)
  63. {
  64. if(x.record>v[j].rec_min && x.record<v[j].rec_max)
  65. flag=1;
  66. }
  67.  
  68. if(flag!=1)
  69. printf("%10s %10s %6d %9.2f %5d/%d/%d\n", x.nome, x.cognome, x.podi, x.record, x.giorno,
  70. x.mese, x.anno);
  71.  
  72. if(podi_min>x.podi)
  73. podi_min=x.podi;
  74.  
  75. if(podi_max<x.podi)
  76. podi_max=x.podi;
  77.  
  78. if(anno<x.anno)
  79. {
  80. anno=x.anno;
  81. if(mese<x.mese)
  82. {
  83. mese=x.mese;
  84. if(giorno<x.giorno)
  85. {
  86. giorno=x.giorno;
  87. }
  88.  
  89. }
  90.  
  91. }
  92. flag=0;
  93. }
  94.  
  95.  
  96. fclose(fa);
  97.  
  98.  
  99. fa=fopen(argv[1], "r");
  100.  
  101. if(fa==NULL)
  102. {
  103. printf("Errore nell'apertura del file %s", argv[1]);
  104. return -5;
  105. }
  106.  
  107. printf("\n");
  108.  
  109. while(fscanf(fa,"%s %s %d %f %d/%d/%d", x.nome, x.cognome, &x.podi, &x.record, &x.giorno, &x.mese, &x.anno)!=EOF)
  110. {
  111.  
  112. if(x.podi==podi_min)
  113. printf("Podi min: %d %s %s\n", x.podi, x.nome, x.cognome);
  114.  
  115. if(x.podi==podi_max)
  116. printf("Podi max: %d %s %s\n", x.podi, x.nome, x.cognome);
  117.  
  118. if(anno==x.anno && mese==x.mese)
  119. printf("Podio piu' recente: %s %s %d/%d/%d\n", x.nome, x.cognome, x.giorno, x.mese, x.anno);
  120.  
  121. }
  122.  
  123. fclose(fa);
  124.  
  125. return 0;
  126. }
  127.  
Runtime error #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
Usage: ./prog filename