Your inner loop only runs for the current value of i
, meaning that you read no values into the first row, 1 into the second row etc.
for (int i = 0; i < 19; i++){
for (int j = 0; j < i; j++){
// ^ wrong
If you want to read a 20x20 matrix, both your inner and outer loop should run for 20 iterations.
for (int i = 0; i < 19; i++){
for (int j = 0; j < 19; j++){
// ^^
Note also that you probably need to add some code to handle any newlines in your input file. After each set of 20 digits, you'll have one (\n)
or two (\r\n
) characters indicating a newline. These are a valid part of the text file but presumably aren't required to be stored in your array.