I've searched stackoverflow and seen every combination of the words in my question, but not the question I have.
I have an array of ints, it happens to be a 2d array.
const int themap[something][something] = { {0, ...
I have a struct that I want to have a pointer to this array in my program
typedef struct {
int** mymap;
} THE_STRUCT
In my program I want to iterate over the values of the array through the struct's pointer, but my data seems to be corrupted if i try to access it through the . syntax
int value;
THE_STRUCT mystruct;
mystruct = (int**) themap;
...
//access the map data from mystruct's pointer?
value = mystruct.mymap[x][y];
//doesn't seem to return correct values
Taking the struct out of the picture the same exact function works if I directly use the array (as a global variable)
int value;
...
//access the map directly
value = themap[x][y]
//everyone is happy!
I would like to use the struct as in reality it will carry other information as well as the fact that I will need to be able to assign the pointer to other arrays with different data.