Tuesday, July 28, 2009

A double-pointer problem!?

I need an 2d array indefinetely long, so I can't use [x][y]. I saw that one can use


char **argv


instead of


char *argv[]


And that's just what I need. So, I made my variable,


char **LevelList


and I faced a problem.


How do I acces a specific place within the array!?


For example, if I had a definite one (arr[100][100]) and I wanted the data on 3,6 I would just use something = arr[3][6]


But how do I do it with this double pointer thing?


I ask this because I'm trying to make a little game in C, (it's my first) and I need to load level names into the array, but I can't know for sure how long and wide it will be...


Please help!

A double-pointer problem!?
char ** is actually a pointer to a pointer and not a multidimensional array. It would be the same as the following:





char *ptr;


char **ptrtoptr=%26amp;ptr;





You could write the code as a linked list which can expand indefinately. The individual nodes in the linked list could contain their own linked lists which would allow you to create multidimensional arrays. You could then write accessors to index into the list.

survey

No comments:

Post a Comment