Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct student {
- char prezime[15];
- char ime[10];
- int brbod;
- };
- int main () {
- FILE *ulaz, *izlaz;
- ulaz=fopen("ORispiti.txt","r");
- if (ulaz==NULL) {
- printf("Greska prilikom otvaranja ulazne datoteke.");
- exit(1);
- }
- izlaz=fopen("Sortispit.txt","w");
- if (izlaz==NULL) {
- printf("Greska prilikom otvaranja izlazne datoteke.");
- fclose(ulaz);
- exit(1);
- }
- struct student PPI[300];
- int i=0, j=0, k=0;
- while(fscanf(ulaz,"%15s %10s %2d\n",PPI[i].prezime,PPI[i].ime,&PPI[i].brbod)!=EOF)
- i++;
- for (j=0; j<i-1; j++)
- for (k=j+1; k<i; k++)
- if (PPI[k].brbod>PPI[j].brbod) {
- struct Student temp=PPI[j];
- PPI[j]=PPI[k];
- PPI[k]=temp;
- }
- j=0;
- while (j<i) {
- fprintf(izlaz,"%-15s %-10s %2d",PPI[i].prezime,PPI[i].ime, PPI[i].brbod );
- j++;
- }
- fclose(ulaz);
- fclose(izlaz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement