I was assigned a mission to create some kind of tic-tac-toe game, in which the player can reverse the game by inputing a negative number of the amount of turns he wants to take the game back in time. And so, I figured i'd need to save each turn of the game in some kind of array that I could then later on approach if I need to.
To sum it up, I need to declare an array of pointers to 2d arrays, and I have no clue how to do that. Heres the code:code if I guessed it right and it is the way of declaring it, can u find any way that it would not work?
CodePudding user response:
typedef struct
{
// something here, probably...
int field[N][N]; // or something similar
Player turn; // whose turn it is now?
// any other data you need
} Board;
Board gameHistory[100]; // array of Board, fixed-size
// or ...
Board* gameHistory; // points into an array of Board, any size
// or ...
Board* gameHistory[100]; // array of pointers to Board, fixed size
// or ...
Board** gameHistory; // points into an array of pointers to Board, any size
Look ma, no pointers to 2D arrays!
CodePudding user response:
int (*arr[M])[N][N];
is what you ask for, but I am quite sure it is not what you actually need