How do you fill a value of a dynamic array of dynamic arrays?

I'm writing a program in which I have to use a matrix to represent a file in code. because it's a file, the size of the matrix is undefined, and therefore the matrix has to be dynamic. I found out that my compiler doesn't like dynamic multidimensional arrays, so I was thinking of this matrix as a dynamic (monodimensional) array of other dynamic (monodimensional) arrays. My program (and thus this example) uses unsigned chars.

1
2
3
4
5
6
7
8
unsigned char variable=something;
unsigned char**matrix=new unsigned char*[lenghtOfMainArray];
for(int rowNumber=0;rowNumber<lenghtOfArray;rowNumber++)
{
  matrix[rowNumber]=new unsigned char[lenghtOfSubArray]
  for(int columnNumber=0;columnNumber<lenghtOfSubArray;columnNumber++)
    //problem
}


my question is: how do I put variable in the first place in the first array of matrix?

matrix[rowNumber]->[columnNumber]=variable;

doesn't seem to work,

*(matrix[rowNumber])[columnNumber]

neither...

Please help!

Kind regards,
Niels Meijer
Use matrix like 2 dimensional array

 
 matrix [ rowNumber ] [ columnNumber ] = variable;
Aaah! I didn't try that one! Thanks man!
It actually really makes sense if you trace back the meaning of all the operators, it's so stupid I didn't try that...
Topic archived. No new replies allowed.