I have the next struct
struct Board
{
int width;
int height;
char **board;
}
And I would like to expand the **board, meaning I need more memory and thus the call to
realloc(). So my question is how do I do that – should I call realloc() on every line in the array separatly and the call it on the entire struct?
Thanks!
You need to call
mallocnotrealloconboard. When you instantiate an object ofBoard, no memory is allocated to the memberboard; so it’s not a question of reallocating memory, but allocating memory toboardin the usual way for multidimensional arrays.Once, you’ve allocated memory, and then if you need to expand
board(e.g.boardwas initially 2×2 and now you want it to be 6×6), callreallocin the same order you calledmallocto initializeboard.