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 br_brod1, br_bod2;
- };
- int main () {
- FILE *ulaz=fopen("ispiti.txt","r");
- if (ulaz==NULL) {
- printf("Greska prilikom otvaranja datoteke.");
- exit(1);
- }
- FILE *izlaz=fopen("usmeni.txt");
- if (izlaz==NULL) {
- printf("Greska prilikom otvaranja izlazne datoteke.");
- fclose(ulaz);
- exit(1);
- }
- int i=0;
- struct Student niz[50], temp;
- 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++;
- int m,n;
- for (m=0; m<i-1; m++) {
- for (n=m+1; n<i; n++) {
- if ((niz[m].br_bod1+niz[m].br_bod2)<(niz[n].br_bod1+niz[n].br_bod2)) {
- temp =niz[m];
- niz[m]=niz[n];
- niz[n]=temp;
- }}
- }
- fclose(ulaz);
- int j=0;
- for (j=0; j<i; j++) {
- if ((niz[i].br_brod1+niz[i].br_bod2)>20)
- fprintf(izlaz,"%15s %10s %d",niz[i].ime,niz[i].prezime,(niz[i].br_brod1+niz[i].br_bod2));
- }
- fclose(ulaz);
- fclose(izla);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement