I am attempting to extract data from a file and the files will contain data such as:
3
Jimmy Bob 40 60 70
Sarah Palin 70 80 30
Alex Trebek 90 100 90
Jimmy Turner 100 50 70
I am trying to grab the first and last name of each person within the file. Then calculate the averages of their grades. I am having a problem with separating the information to the respected data types (i.e, Put Jimmy in the firstname variable and Bob in the last name variable via an array). Lastly, I am trying to collect all the grades in a 2D array. How would I do this? I would imagine it is possible to read from a file and tell the program to skip spaces, but how?
// ###Function2### Extracts data from file and divides it to the appropriate data type.
void ReadFile(ifstream& InFile, int& line1, string firstname[][COL], string lastname[][COL], int grades[][COL]) {
int row = 0, col;
InFile >> line1;
InFile.ignore(1000000, '\n');
for (row = 0; row < line1; row++)
for (col = 0; col < line1; col++)
getline(InFile, firstname[row][col], ' ');
getline(InFile, lastname[row][col], ' ');
InFile.ignore(1000000, '\n');
}
// ###Function3### Outputs the results from function2.
void PrintGrades(int& line1, string firstname[][COL], string lastname[][COL], int grades[][COL]) {
int row = 0, col;
for (row = 0; row < line1; row++)
for (col = 0; col < line1; col++)
cout << firstname[row][col] << " ";
cout << lastname[row][col] << " ";
}
Could I possibly use:
void ReadFile(ifstream& InFile, int& line1, string firstname[COL], string lastname[COL], int grades[][COL]) {
int row = 0, col = 0;
InFile >> line1;
InFile.ignore(1000000, '\n');
for (row = 0; row < EOF; row++)
getline(InFile, firstname[row][col], ' ');
getline(InFile, lastname[row][col], ' ');
InFile.ignore(1000000, '\n');
}
to extract the file?