Hey, I'm trying to program a tic tac toe game to the specifications of my professor, and im having an issue with pointers and 2D arrays. Anyone know what is wrong with this program (dont worry about the fact that i didnt use #include to load some stuff, this is only a portion of the program)
If you can help me please post a response in a simple explination that doesnt go into technical terms. I know basics about this language but i dont know everything.
The warning happens in the main function, when i use the function 'play'. Something isnt working with my 2D array being used with pointers.
void play (char *board[3][3], int *player)
{
int x,y = 0;
do
{
printf("Player %d: choose a location: (x, then y)", *player);
scanf("%d %d", &x, &y);
if (*board[x][y] != ' ')
printf("Location already occupied\n");
}
while (*board[x][y]!=' ');
if (*player = 1)
*board[x-1][y-1]='X';
else if (*player = 2)
*board[x-1][y-1]='O';
else
*board[x-1][y-1]='?';
}
int main()
{
char board[3][3];
int i,l;
for (i = 0; i < 3; i++)
for (l = 0; l <3;l++)
board[l]='?';
int player = 1;
play (&board,&player);
return 0;
}
If you can help me please post a response in a simple explination that doesnt go into technical terms. I know basics about this language but i dont know everything.
The warning happens in the main function, when i use the function 'play'. Something isnt working with my 2D array being used with pointers.
void play (char *board[3][3], int *player)
{
int x,y = 0;
do
{
printf("Player %d: choose a location: (x, then y)", *player);
scanf("%d %d", &x, &y);
if (*board[x][y] != ' ')
printf("Location already occupied\n");
}
while (*board[x][y]!=' ');
if (*player = 1)
*board[x-1][y-1]='X';
else if (*player = 2)
*board[x-1][y-1]='O';
else
*board[x-1][y-1]='?';
}
int main()
{
char board[3][3];
int i,l;
for (i = 0; i < 3; i++)
for (l = 0; l <3;l++)
board[l]='?';
int player = 1;
play (&board,&player);
return 0;
}