Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Napisati program koji prvo pročita koliko redaka ima datoteka, tj. koliko ima studenata
- zapisanih u datoteci. Nakon toga potrebno je dinamički alocirati prostor za niz struktura
- studenata (ime, prezime, bodovi) i učitati iz datoteke sve zapise. Na ekran ispisati ime,
- prezime,apsolutni i relativni broj bodova*/
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct student
- {
- char ime[20];
- char prezime[20];
- int brojBodova;
- };
- int main()
- {
- int brojStudenata = 0;
- char a = 0;
- struct student *niz;
- FILE *f;
- f = fopen("studenti.txt", "r");
- if (f == NULL)
- printf("File not found");
- while (!feof(f))
- {
- a = fgetc(f);
- if (a == '\n')
- {
- brojStudenata++;
- }
- }
- fclose(f);
- brojStudenata++;
- printf("%d", brojStudenata);
- niz = malloc(brojStudenata * sizeof(struct student));
- getchar();
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement