I know, a lot was told about it, yet I couldn't find an explicit reference to what I need.
I need to have a struct member which will point to a two-dimensional array. The array size isn't fixed, each instance of the struct will point to an array with a different size.
I thought about the following way:
struct towDimByPtr
{
int NumRow;
int NumCol;
int* ptr2TwoDim;
};
Then I'll have globals:
int arr1[30][90];
int arr2[20][10];
towDimByPtr towDim1;
towDimByPtr towDim2;
At init I'll do:
towDim1.ptr2TwoDim = arr1;
towDim1.NumRow = 30;
towDim1.NumCol = 90;
towDim2.ptr2TwoDim = arr2;
towDim2.NumRow = 20;
towDim2.NumCol = 10;
Finally when accessing an element I'll use:
towDim1[curr_row*NumCol + curr_col]
My question: Will this always work.