I am writing a Tic-Tac-Toe program and am writing a function for the player's turn. I am passing in the Tic-Tac-Toe board (a 3x3 array) in the form of the pointer, b. The only problem is that on the last line I get the error in the title.
Subscripted value is neither array nor pointer nor vector: b[PlayerCoordsX][PlayerCoordsY] = "x";
Just for testing I've tried multiple different = values. Both characters and numerical values do not fix the issue.
Here is the abbreviated code with (what I hope) are the relevant bits:
void PlayerTurn(int *b);
...
int main(void)
{
int Board[2][2];
int (*b)[2][2];
b = &Board;
...
void PlayerTurn(int *b);
...
return 0;
}
void PlayerTurn(int *b)
{
int PlayerCoordsX, PlayerCoordsY;
while ((PlayerCoordsX != 1 || PlayerCoordsX != 2 || PlayerCoordsX != 3) && (PlayerCoordsY != 1 || PlayerCoordsY != 2 || PlayerCoordsY != 3))
{
printf("Enter the X coordinate you would like to use:");
scanf("%i", &PlayerCoordsX);
PlayerCoordsX = PlayerCoordsX - 1;
printf("Enter the Y coordinate you would like to use:");
scanf("%i", &PlayerCoordsY);
PlayerCoordsX = PlayerCoordsY - 1;
}
b[PlayerCoordsX][PlayerCoordsY] = "x";
}
Board[2][2]? That's only 2x2. - Barmar