Im writing a game in c and i want to change player in every step. So i create i function to do this.
struct Node{
char player[4];
int cubesRemaining;
struct Node *left;
struct Node *right;
};
char *switchPlayer(struct Node *n){
if (strcmp(n->player, "MAX") == 0){
strcpy(n->player, "MIN");
return (n->player);
}
else{
strcpy(n->player, "MAX");
return (n->player);
}
}
Now i want to build the game tree and i create another function using recursion. Im also using the switchplayer function but im getting an error message.Here is my code:
struct Node *buildGameTree(int ncubes, char *player){
struct Node *cube = calloc(1, sizeof(struct Node));
cube->cubesRemaining = ncubes;
strcpy(cube->player, player);
if (cube->cubesRemaining >= 1){
cube->left = buildGameTree(ncubes - 1, switchPlayer(cube->player));
}
if (cube->cubesRemaining >= M){
cube->right = buildGameTree(ncubes - K, switchPlayer(cube->player));
}
return (cube);
}
The error message is: Warning passing argument 1 of switchplayer from incompatible pointer type
You define switchplayer
to take a struct Node*
type, but you're passing cube->player
which is a char *
; therefore, you are passing an incompatible pointer type.
You probably want to just pass cube
and not cube->player
as in
cube->left = buildGameTree(ncubes -1, switchPlayer(cube));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments