My ReadFile function is not reading my entire file. The file has lines of information each relating to one student.
The function (or the while loop perhaps) is reading the first two records and then exits the loop. It is reading everything correctly but why does it not continue reading the entire file (which has 13 records in it)?
I've tried while(!infile.eof())
but the program doesn't even run with this.
Here is my ReadFile block:
void ReadFile() {// Reads data file into array
ifstream infile;
infile.open(cTextFileName);
if (!infile.good()) {
cout << "Cant find text data file!" << endl;
exit(1);
}
int i = 0;
int status;
//bool endOfFile = infile.eof();
infile >> gRecs[i].StudentNo;
while (infile) {
infile >> gRecs[i].FirstName;
infile >> gRecs[i].LastName;
infile >> gRecs[i].NumSubjects;
//cout << "ENTERED WHILE LOOP" << endl;
for (int j = 0; j < gRecs->NumSubjects; j++) {
infile >> gRecs[i].Subjects[j].Code;
infile >> status;
if (status == 0) {
gRecs[i].Subjects[j].Status == eEnrolled;
} else if (status == 1) {
gRecs[i].Subjects[j].Status == eProvisional;
} else {
gRecs[i].Subjects[j].Status == eWithdrawn;
}
infile >> gRecs[i].Subjects[j].Mark;
}
i++;
infile >> gRecs[i].StudentNo;
}
gNumRecs = i;
infile.close();
infile.clear();
cout << gNumRecs << " Records read!" << endl;
}
for (int j = 0; j < gRecs->NumSubjects; j++) {
should be
for (int j = 0; j < gRecs[i].NumSubjects; j++) {