Reading and saving a matrix from a txt on a variable

  c++, visual-c++

I am working on a practice that requieres to do multiple things with matrix. I have to change lines, columns, diagonals …

So i have created a new type which is:

#define DIM_MAX  64


typedef char tMatrizChar[DIM_MAX][DIM_MAX];

Now a matrix is passed to me by a .txt been the two first number the number of lines and columns and then the matrix:

4 5

0 0 6 6 6 

0 6 6 6 6 

0 6 6 0 6 

0 9 6 0 6

I am using a code from another post to read the txt line by line:

input_file.open("input_file.txt");

// Read the file one line at a time
while (std::getline(input_file, line))
{
    // Do your thing
}

input_file.close();

My first problem is that i dont know how to resize the matrix from 64×64 (a size preset by the exercise for all matrices) with the size told by the two first numbers.
And my second is that when the program is reading i dont know how to writte each number from the txt to my varible where it belongs. I am trying to writte a nested for but i dont have clue of how to orient it.

Would anyone know how to do it?

P.D.: sorry for bad english

Source: Windows Questions C++

LEAVE A COMMENT