I want to read a list of names from a text file like this
Johnny
Bertha
Arty
And put them into a 2-D array with the amount of rows corresponding with the amount of names on the list, in this example 3; and the amount of columns corresponding with the maximum amount of characters to a name, let's say 10.
The array I want to end up with should be sized like this.
names[3][10]
The code I have is broken in the sense that it does not distinguish the line breaks and just fills the array as soon as possible, I want to end up filling the extra space in a row of the array with null characters so the array looks like this.
[J][o][h][n][n][y][\0][\0][\0][\0]
[B][e][r][t][h][a][\0][\0][\0][\0]
[A][r][t][y][\0][\0][\0][\0][\0][\0] (3 rows and 10 columns here)
I used .get but think I need to use the .getline function but I am lost as how I would use it in a nested for loop properly, or is it simpler? Here is the code fragment where I read the names from a text file (10 rows and 9 columns here)
while (! file1.eof()){
for (int i = 0; i < 10; i++){
for( int j = 0; j < 9; j++){
temp = file1.get();
names[i][j] = temp;
}
}}