J
John Hanley
I need to allocate memory dynamically for a two dimensional array. It's
basically a pointer to an array of 2 element arrays: I declared it as long
int ** arr. The number of two element arrays are unknown at compile time.
I am not quite sure if I allocated memory properly for this (I am sure I
didn't).
arr = malloc((sizeof(long int)*2)*number_of_elements)
when I debug it, I have access to arr[0][0], arr[1][0], arr[2][0], etc...
but not arr[0][1]. It tells me it can't access memory which leads me to
believe I don't quite have my memory allocation and/or declaration correct.
I have tried a few different ways, but I obviously haven't found the right
way to do it yet.
Any suggestions?
Thanks a bunch!
John
basically a pointer to an array of 2 element arrays: I declared it as long
int ** arr. The number of two element arrays are unknown at compile time.
I am not quite sure if I allocated memory properly for this (I am sure I
didn't).
arr = malloc((sizeof(long int)*2)*number_of_elements)
when I debug it, I have access to arr[0][0], arr[1][0], arr[2][0], etc...
but not arr[0][1]. It tells me it can't access memory which leads me to
believe I don't quite have my memory allocation and/or declaration correct.
I have tried a few different ways, but I obviously haven't found the right
way to do it yet.
Any suggestions?
Thanks a bunch!
John