I am using the following function to load my parallel arrays from the information in a file. The file consists of 5 columns and 10 rows. Each column is filled with random numbers (1-65) and are separated by only tabs. When I call this function then output the arrays, the first number in the file is completely skipped and the second and third values are switched.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int loadArrays(int playerNum[], int hits[], int atBats[], int runs[], int rbis[], double batAvg[], int SIZE)
{
ifstream inputFile;
inputFile.open("playerstats.txt");
short i = 0;
while (inputFile >> playerNum[i])
{
inputFile >> playerNum[i] >> atBats[i] >> hits[i] >> runs[i] >> rbis[i];
i++;
}
return (i + 1);
}
** UPDATE**
I figured out why the 2nd and third number are switched. (I the arguments that I was passing and the parameters were switched). Still trying to figure out how to fix the read position problem.
It is skipping every other line instead of the first digit.
while (inputFile >> playerNum[i])
So it appears this code is moving my read position every time it loops. Is there a way that I can move the read position back or is there a better way for me to test if there is still contents in the file?