fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct
  6. {
  7. float rec_min;
  8. float rec_max;
  9. } range;
  10.  
  11. typedef struct
  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. {
  70. printf("%10s %10s %6d %9.2f %5d/%d/%d\n", x.nome, x.cognome, x.podi, x.record, x.giorno,
  71. x.mese, x.anno);
  72.  
  73. if(podi_min>x.podi)
  74. podi_min=x.podi;
  75.  
  76. if(podi_max<x.podi)
  77. podi_max=x.podi;
  78.  
  79. if(anno<x.anno)
  80. {
  81. anno=x.anno;
  82. if(mese<x.mese)
  83. {
  84. mese=x.mese;
  85. if(giorno<x.giorno)
  86. {
  87. giorno=x.giorno;
  88. }
  89.  
  90. }
  91.  
  92. }
  93. }
  94. flag=0;
  95.  
  96. }
  97.  
  98.  
  99. fclose(fa);
  100.  
  101.  
  102. fa=fopen(argv[1], "r");
  103.  
  104. if(fa==NULL)
  105. {
  106. printf("Errore nell'apertura del file %s", argv[1]);
  107. return -5;
  108. }
  109.  
  110. printf("\n");
  111.  
  112. 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)
  113. {
  114.  
  115. if(x.podi==podi_min)
  116. printf("Podi min: %d %s %s\n", x.podi, x.nome, x.cognome);
  117.  
  118. if(x.podi==podi_max)
  119. printf("Podi max: %d %s %s\n", x.podi, x.nome, x.cognome);
  120.  
  121. if(anno==x.anno && mese==x.mese)
  122. printf("Podio piu' recente: %s %s %d/%d/%d\n", x.nome, x.cognome, x.giorno, x.mese, x.anno);
  123.  
  124. }
  125.  
  126. fclose(fa);
  127.  
  128. return 0;
  129. }
  130.  
Runtime error #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
Usage: ./prog filename