So i have a file that has teams and scores, i need to read the team into a 2D array of chars and then their score following into a array of ints.
This is my current code for my function, how do i get this to stop reading after the team name is complete then store the score in a seperate array?
void getData (char array [][COLS], int rows, int scores [])
{
ifstream inFile; //Input file stream object
//Open the file
inFile.open ("scores.txt");
if (!inFile)
{
cout << "Error opening data file!\n";
exit(102);
}
for (int r = 0; r < rows; r++)
{
{
//reads through columns
for (int c = 0; c < COLS; c++)
{
inFile >> array[r][c];
}
}
}
for (int count = 0; count < ROWS; count++)
{
for(int i = 0; i < COLS; i++)
{
cout << array[count][i];
}
}
inFile.close();
}
My input file is as follows:
Jaquars 23
Colts 23
49ers 13
Lions 13
Titans 7
Redskins 38
Cardinals 14
Buccaneers 36
Seahawks 30
Lions 24
Bears 28
Packers 23
Bears 14
Rams 22
Texans 6
Packers 34