#include #include #include #define MAXS 100 typedef struct student{ char *ime; char *prezime; int poena; } student; int main(){ int ucitano=0; int alocirano=5; int tokena; char ime[MAXS]; char prezime[MAXS]; char linija[2*MAXS]; int poena; int i; student *studenti = malloc(sizeof(student)*alocirano); if(studenti==NULL){ printf("Greska u alokaciji.\n"); exit(EXIT_FAILURE); } while(1){ fgets(linija,MAXS,stdin); if(strcmp(linija,"\n")==0) break; sscanf(linija,"%s %s %d",ime,prezime,&poena); if(ucitano>=alocirano){ alocirano +=5; studenti = realloc(studenti,alocirano*sizeof(student)); } studenti[ucitano].ime = malloc(strlen(ime)+1); studenti[ucitano].prezime = malloc(strlen(prezime+1)); if(studenti[ucitano].ime==NULL || studenti[ucitano].prezime==NULL){ printf("Nije uspela alokacija imena ili prezimena.\n"); exit(EXIT_FAILURE); } strcpy(studenti[ucitano].ime, ime); strcpy(studenti[ucitano].prezime, prezime); studenti[ucitano].poena = poena; ucitano++; } for(i=0; i