Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Hello,
In my .h file, i have a 2d char array like this:
char grid [10][10]
Everything is fine but i can't change the size like:
grid = new grid[2][7]
I need to access the "grid" from everywhere in my .m file and i know the size only in the .m file.
What can i do ?
0 •
Replies
deal.gameweaver.com
guessem.gameweaver.com
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThere's something wrong with that.
If you want to access C/C++ data from Objective-C, then you should put your C/C++ data into a class,
then dynamically allocate a pointer to it. Then access your data through that pointer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf you want to be able to resize a C array, you need to create it with malloc and release it with free: Then you have to release it with free:
free(grid);To resize, you'd have to free the old memory and malloc a new array.
Then you have to use index math to address the memory: Since the above approach has a height and a width, you can expose those to the rest of your program.
Obviously it would be better if the grid was a char* property and height and width were readonly properties, and you had a grid_resize method.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf you want to be lazy about it, declare a 2D array with a max dimensions:
#define MAX_X 10
#define MAX_Y 10
char grid [MAX_X][MAX_Y];
Then use variables to control how large you want your array:
int max_x = 5;
int max_y = 7;
Your code should work the same as before.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThe lazy way was my first idea, just size the grid to the max and use only a part of it. This should work but i don't want to use "bad coding way".
The idea to put the grid into a class sounds better, i will look on how to do it but i suppose i should use Duncan C method to assign the grid size in this class. Looks not so easy...
Edit:
I just remember that i must think Objects. I will try to make my grid a object with methods like getValueOf[x][y] and setValueOf[x][y] (if this is possible like in java).
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome