I am attempting to read in unknown number of scores from a text file and assign each score to an element in the int scores[100] array with the following code:
1 2 3 4 5 6 7 8 9
void getData ( int score[], int& len, fstream& data )
{
// continue to read data until end of file reached
while ( !data.eof() )
{
data >> score[len];
len++;
}
}
After assigning all scores to the array, I perform a few other functions. Each time I read in a score, I want to increase my len variable to identify how many scores were read in. The problem is there are exactly 67 scores in the text file, so that means the assignment will end at scores[66]. However, when I output this info it seems it has counted 68 scores and I have no idea how that's possible. I do see a problem with the way I'm incrementing len++. Upon reaching eof, I'm increasing len one more time to 67 which is false, but that doesn't explain how its counting to 68. If anyone has any feedback it would be greatly appreciated!