Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by L10_Studenti_ocjene ( 3 years ago )
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Ocjena {
char naziv_predmeta[51];
int ocjena;
};
struct Student {
char ime[21], prezime[21];
int br_ocjena;
struct Ocjena ocjene[100];
};
int ucitaj(struct Student studenti[], int kapacitet) {
int broj_studenata = 0, brojac = 0, i = 0, j = 0, k = 0;
struct Student pomocni;
FILE *citaj = fopen("input.txt", "r");
if (citaj == NULL) {
printf("Datoteka ne postoji\n");
exit(0);
}
if (fscanf(citaj, "%s %s %s %d\n", studenti[0].ime, studenti[0].prezime, studenti[0].ocjene[0].naziv_predmeta, &studenti[0].ocjene[0].ocjena) == 4) {
studenti[0].br_ocjena = 1;
broj_studenata++;
while (broj_studenata < kapacitet && fscanf(citaj, "%s %s %s %d\n", pomocni.ime, pomocni.prezime, pomocni.ocjene[0].naziv_predmeta, &pomocni.ocjene[0].ocjena) == 4) {
for (i = 0; i < broj_studenata; i++) {
if (strcmp(studenti[i].ime, pomocni.ime) == 0 && strcmp(studenti[i].prezime, pomocni.prezime) == 0) {
brojac = studenti[i].br_ocjena;
strcpy(studenti[i].ocjene[brojac].naziv_predmeta, pomocni.ocjene[0].naziv_predmeta);
studenti[i].ocjene[brojac].ocjena = pomocni.ocjene[0].ocjena;
studenti[i].br_ocjena++;
break;
}
}
if (i == broj_studenata) {
studenti[i].br_ocjena = 0;
for (k = 0; pomocni.ime[k] != '\0'; k++) {
studenti[i].ime[k] = pomocni.ime[k];
}
studenti[i].ime[k] = '\0';
for (k = 0; pomocni.prezime[k] != '\0'; k++) {
studenti[i].prezime[k] = pomocni.prezime[k];
}
studenti[i].prezime[k] = '\0';
for (k = 0; pomocni.ocjene[0].naziv_predmeta[k] != '\0'; k++) {
studenti[i].ocjene[0].naziv_predmeta[k] = pomocni.ocjene[0].naziv_predmeta[k];
}
studenti[i].ocjene[0].naziv_predmeta[k] = '\0';
studenti[i].ocjene[0].ocjena = pomocni.ocjene[0].ocjena;
studenti[i].br_ocjena++;
broj_studenata++;
}
}
}
fclose(citaj);
return broj_studenata;
}
int main() {
return 0;
}
Revise this Paste