I am trying to read this data file into a struct. however i am having trouble doing so. here is the code i have so far. the part i am having trouble with is the readData function
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstring>
#include<string>
using namespace std;
const int CAP = 100;
const int MAX_CHAR = 31;
int totalLines = 0;
struct Student
{
char name[31];
int score[10];
};
int readData(ifstream& iFile, Student list[]);
void findLowestEach(Student list[], int size);
void findHighestEach(Student list[], int size);
void calcAverage(Student list[], int size);
int main()
{
Student list[CAP];
ifstream inFile;
inFile.open("data.txt");
if (!inFile.is_open()) {
cout << "Error: File cannot be opened.\n";
exit(1);
}
readData(inFile, list);
// calls all of the other functions
//readData(inFile, list[]);
//findLowestEach(list[], size);
//cout << endl;
//findHighestEach(scores, names);
//cout << endl;
//calcAverage(scores, names);
}
int readData(ifstream& iFile, Student list[])
{
int i = 0;
while (!iFile.eof())
iFile >> list[i].name;
for (int i = 0; i < 10; i++)
{
iFile >> list[i].score;
}
return 0;
}
here is the data file
Bob 56 67 83 76 84 94 68 86 78 56
John 76 89 95 64 78 34 99 89 104 98
Joe 65 68 89 78 45 69 98 101 99 89
Amy 86 77 89 76 94 54 78 89 78 66
Nick 76 69 95 94 78 64 99 89 110 88
Alex 95 88 89 78 95 69 88 101 99 89
Marga 96 67 89 76 64 94 98 83 78 56
Mike 76 89 95 64 78 34 99 89 104 98
Bella 85 68 89 78 45 69 98 101 99 89
Priya 86 77 89 76 94 94 78 89 78 96
Karen 78 69 95 94 78 94 99 89 110 88
Amit 95 88 79 78 95 89 88 101 99 89
Just hoping for a push in the right direction for reading in the data file. I think that I am sort of on the right track but im not sure