I am assuming that you need to keep track of the data as if it is still in a two dimensional array after you read it in. Basically, you have to keep track of three things. You need an index for the one dimensional array, and you need a “row” index and a “column” index for the two dimensional array. Obviously, the size of the 1D array must be at least the number of rows times the number of columns. The relationship between the indices is:

1D_Index = Row_Index * LengthOf Row + Column_Index

Of course, you can reverse the rows and columns, if that works better for you.

Do you know the number of rows and columns before you start? This is really kind of important if you are going from one array to the other.

If my initial assumption was incorrect, and once you read in the data, you don’t need to keep track of what row it was in, things are simpler. You just need an index for the one dimensional array. Read each piece of data in, starting at the first line (row), and just store it into the 1D array using the index. Increment the index after each reading each piece of data, regardless of whether you change lines. Most input methods are actually set up to read in data this way, and will go left-to-right, line by line.

By the way, when the compiler allocates memory for a multi-dimensional array, it still allocates a block of sequential memory addresses. So, the memory actually ends up allocated like a one dimensional array.

To answer your question:
Do you know the number of rows and columns before you start? This is really kind of important if you are going from one array to the other.

- Yes I'll know the size of the matrix. (e.g. 10 x 10)

I think I have something of an idea on how to read the matrix in:

I'm going to have a function that reads the contents of the text file into an array. I'm unsure whether or not I will just define the file inside main and then process the file and store it into an array..

OR actually read the contents of the file inside main and then pass the array through a method..