Advertisement
sellmmaahh

OR-tut13-zad2_1

Aug 10th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. struct Student
  4. { char prezime[15];
  5. char ime[10];
  6. int br_brod1, br_bod2;
  7. };
  8.  
  9. int main () {
  10.     FILE *ulaz=fopen("ispiti.txt","r");
  11.     if (ulaz==NULL) {
  12.         printf("Greska prilikom otvaranja datoteke.");
  13.         exit(1);
  14.     }
  15.     FILE *izlaz=fopen("usmeni.txt");
  16.     if (izlaz==NULL) {
  17.         printf("Greska prilikom otvaranja izlazne datoteke.");
  18.         fclose(ulaz);
  19.         exit(1);
  20.     }
  21.    
  22.     int i=0;
  23.     struct Student niz[50], temp;
  24.     while (fscanf(ulaz,"%15s %10s %d %d",&niz[i].prezime,&niz[i].ime, &niz[i].br_brod1,&niz[i].br_bod2)!=EOF && i<50) i++;
  25.    
  26.     int m,n;
  27.     for (m=0; m<i-1; m++) {
  28.         for (n=m+1; n<i; n++) {
  29.                 if ((niz[m].br_bod1+niz[m].br_bod2)<(niz[n].br_bod1+niz[n].br_bod2)) {
  30.                         temp =niz[m];
  31.                 niz[m]=niz[n];
  32.                 niz[n]=temp;
  33.                 }}
  34.     }
  35.     fclose(ulaz);
  36.     int j=0;
  37.     for (j=0; j<i; j++) {
  38.             if ((niz[i].br_brod1+niz[i].br_bod2)>20)
  39.             fprintf(izlaz,"%15s %10s %d",niz[i].ime,niz[i].prezime,(niz[i].br_brod1+niz[i].br_bod2));
  40.     }
  41.     fclose(ulaz);
  42.     fclose(izla);
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement