Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct student
- {
- char ime[20];
- char prezime[20];
- int ocjene[10];
- };
- float Prosjek(struct student s)
- {
- int i,suma=0;
- for(i=0; i<10; i++)
- {
- suma+=s.ocjene[i];
- }
- return suma/10;
- }
- void sort(struct student* niz,int vel)
- {
- int i,j;
- struct student temp;
- for(i=0; i<vel; i++)
- {
- for(j=i+1; j<vel; j++)
- {
- if(Prosjek(niz[i])>Prosjek(niz[j]))
- {
- temp=niz[i];
- niz[i]=niz[j];
- niz[j]=temp;
- }
- }
- }
- }
- int main()
- {
- int i=0;
- struct student niz[100];
- FILE *Ulaz=fopen("studenti.txt", "r");
- if(Ulaz==NULL)
- {
- printf("Greska pri otvaranju.");
- exit(1);
- }
- FILE *Izlaz=fopen("streberi.txt", "w");
- if(Izlaz==NULL)
- {
- printf("Greska pri otvaranjuss datoteke.");
- fclose(Ulaz);
- exit(1);
- }
- /*
- printf("Unesite ime i prezime studenta:");
- fscanf(Ulaz,"%20s%20s",ime, prezime);
- printf("Unesi ocjene:");
- for(i=0;i<10;i++){
- fscanf(Ulaz,"%d",&);
- }*/
- 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++;
- printf("%d%d", niz[0].ocjene[0], niz[0].ocjene[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement