Jul 9, 2016 at 12:15pm UTC
What does ucitajStudente do ? Do you actually read from the file ?
Jul 9, 2016 at 12:55pm UTC
Hi,
1 2 3 4
while (feof(f)) {
ucitajStudente(f, &(studenti[brStudenta]));
brStudenta++;
}
I am not very sure why this loops forever in the first place. Maybe your input file is empty (or your program doesn't have permission to access the file).
However, you may try this :
1 2 3 4 5 6 7
std::cout << ((!feof(f)) ? "Start reading..." : "Error : File is empty (EOF)" ) << "\n\n" ;
while (!feof(f)) {
ucitajStudente(f, &(studenti[brStudenta]));
brStudenta++;
std::cout << "#" << brStudenta << " student(s) read" << std::endl;
}
Last edited on Jul 9, 2016 at 2:04pm UTC
Jul 9, 2016 at 12:57pm UTC
Can you let us see the content of the file prijemni.txt?
Edit : Let us know your program output if there is one.
Last edited on Jul 9, 2016 at 1:07pm UTC
Jul 9, 2016 at 1:44pm UTC
Yes, here is the prijemni.txt:
1 103 John Smith 39.14 60 99.14
2 183 John Doe 38.58 60 98.58
3 41 Bernard Ames 38.16 60 98.16
4 88 Timothy Morris 38.08 60 98.08
5 124 Christopher Moss 37.44 60 97.44
6 347 Tim Bitner 37.24 60 97.24
There is not program output, just a blank CMD window since while is running infinity.
Thanks
Jul 9, 2016 at 2:07pm UTC
Ok, did you really ran my solution?
Anyway, I have updated it. Let me know your output outcome.
Jul 9, 2016 at 2:22pm UTC
fscanf(f, "%d %d %s %s %fl %d %fl" , &(s->brLista), &(s->brPrijave), &(s->ime), &(s->prezime), &(s->bodoviSrednja), &(s->bodoviPrijemni), &(s->bodoviUkupan));
It is not %fl
. It is %lf
. Also put a space character at the end of the format string, which tells fscanf() to eat any whitespace characters, including new-lines ('\n')
So :
fscanf(f, "%d %d %s %s %lf %d %lf " , &(s->brLista), &(s->brPrijave), &(s->ime), &(s->prezime), &(s->bodoviSrednja), &(s->bodoviPrijemni), &(s->bodoviUkupan));
Jul 9, 2016 at 2:28pm UTC
Thank you so much, the fscanf part was the only problem.
It works now and I get my results. Thanks again!
Have a great day!