Advertisement
mali_cox

Ne znam dalje

Jan 31st, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct student
  5. {
  6.     char ime[20];
  7.     char prezime[20];
  8.     int ocjene[10];
  9. };
  10.  
  11. float Prosjek(struct student s)
  12. {
  13.     int i,suma=0;
  14.     for(i=0; i<10; i++)
  15.     {
  16.         suma+=s.ocjene[i];
  17.     }
  18.     return suma/10;
  19. }
  20.  
  21. void sort(struct student* niz,int vel)
  22. {
  23.     int i,j;
  24.     struct student temp;
  25.     for(i=0; i<vel; i++)
  26.     {
  27.         for(j=i+1; j<vel; j++)
  28.         {
  29.             if(Prosjek(niz[i])>Prosjek(niz[j]))
  30.             {
  31.                 temp=niz[i];
  32.                 niz[i]=niz[j];
  33.                 niz[j]=temp;
  34.             }
  35.         }
  36.     }
  37. }
  38.  
  39. int main()
  40. {
  41.     int i=0;
  42.  
  43.     struct student niz[100];
  44.  
  45.     FILE *Ulaz=fopen("studenti.txt", "r");
  46.                if(Ulaz==NULL)
  47.     {
  48.         printf("Greska pri otvaranju.");
  49.         exit(1);
  50.     }
  51.  
  52.     FILE *Izlaz=fopen("streberi.txt", "w");
  53.     if(Izlaz==NULL)
  54.     {
  55.         printf("Greska pri otvaranjuss datoteke.");
  56.         fclose(Ulaz);
  57.         exit(1);
  58.     }
  59.     /*
  60.     printf("Unesite ime i prezime studenta:");
  61.     fscanf(Ulaz,"%20s%20s",ime, prezime);
  62.     printf("Unesi ocjene:");
  63.     for(i=0;i<10;i++){
  64.         fscanf(Ulaz,"%d",&);
  65.     }*/
  66.     while(fscanf(Ulaz,"%20s%20s%d%d%d%d%d%d%d%d%d%d", niz[i].ime, niz[i].prezime, &niz[i].ocjene[0], &niz[i].ocjene[1], &niz[i].ocjene[2], &niz[i].ocjene[3], &niz[i].ocjene[4], &niz[i].ocjene[5], &niz[i].ocjene[6], &niz[i].ocjene[7], &niz[i].ocjene[8], &niz[i].ocjene[9])!=EOF && i<10) i++;
  67.  
  68.     printf("%d%d", niz[0].ocjene[0], niz[0].ocjene[1]);
  69.  
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement