Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct gara{
  5. char atleta [20];
  6. int punteggio;
  7. }atleti;
  8. int main()
  9. {
  10. FILE *compet,*newf;
  11. int i,j,v[100],g,h=0,k,punteggio,max=0;
  12. char temp[20];
  13. atleti var[100];
  14. if((compet=fopen("gara.txt","r"))==NULL)
  15. {
  16. printf("errore apertura file");
  17. return 1;
  18. }
  19. for(i=0;fscanf(compet,"%s %d",var[i].atleta,&var[i].punteggio)!=EOF;i++)
  20. {
  21. punteggio=var[i].punteggio;
  22. v[i]=var[i].punteggio;
  23.  
  24. for(j=i;j>=0;j--)
  25. {
  26.  
  27. if(punteggio>v[j])
  28. {
  29. v[j+1]=v[j];
  30. v[j]=punteggio;
  31.  
  32. }
  33. }
  34.  
  35. for(j=i;j>=0;j--)
  36. {
  37. strcpy(temp,var[i].atleta);
  38. if(strcmp(temp,var[j].atleta)<0)
  39. {
  40. strcpy(var[j+1].atleta,var[j].atleta);
  41. strcpy(var[j].atleta,temp);
  42. }
  43.  
  44. }
  45. }
  46.  
  47. if((newf=("garaord.txt","w"))==NULL)
  48. {
  49. printf("errore scrittura nuovo file");
  50. }
  51. for(k=0;k<=i;i++)
  52. {
  53. fprintf(newf,"%s %d",var[k].atleta,var[k].punteggio);
  54. fprintf(newf,"/n");
  55. }
  56. for(g=0;g<i;g++)
  57. {
  58. if(v[g]==var[g].punteggio && h<=3)
  59. {
  60. h++;
  61. strcpy(temp,var[g].atleta);
  62. printf("il %d classificato %s",h,temp);
  63. }
  64. }
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement