Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct gara{
- char atleta [20];
- int punteggio;
- }atleti;
- int main()
- {
- FILE *compet,*newf;
- int i,j,v[100],g,h=0,k,punteggio,max=0;
- char temp[20];
- atleti var[100];
- if((compet=fopen("gara.txt","r"))==NULL)
- {
- printf("errore apertura file");
- return 1;
- }
- for(i=0;fscanf(compet,"%s %d",var[i].atleta,&var[i].punteggio)!=EOF;i++)
- {
- punteggio=var[i].punteggio;
- v[i]=var[i].punteggio;
- for(j=i;j>=0;j--)
- {
- if(punteggio>v[j])
- {
- v[j+1]=v[j];
- v[j]=punteggio;
- }
- }
- for(j=i;j>=0;j--)
- {
- strcpy(temp,var[i].atleta);
- if(strcmp(temp,var[j].atleta)<0)
- {
- strcpy(var[j+1].atleta,var[j].atleta);
- strcpy(var[j].atleta,temp);
- }
- }
- }
- if((newf=("garaord.txt","w"))==NULL)
- {
- printf("errore scrittura nuovo file");
- }
- for(k=0;k<=i;i++)
- {
- fprintf(newf,"%s %d",var[k].atleta,var[k].punteggio);
- fprintf(newf,"/n");
- }
- for(g=0;g<i;g++)
- {
- if(v[g]==var[g].punteggio && h<=3)
- {
- h++;
- strcpy(temp,var[g].atleta);
- printf("il %d classificato %s",h,temp);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement