C 既不是参数也不是指针
数组是新手,我不断得到一个错误,即在selectLocation函数中,下标值既不是指针也不是向量。这只是tic tac toe计划的开始。我做错了什么C 既不是参数也不是指针,c,arrays,C,Arrays,数组是新手,我不断得到一个错误,即在selectLocation函数中,下标值既不是指针也不是向量。这只是tic tac toe计划的开始。我做错了什么 void selectLocation(char board[],int choice); void displayBoard(char[]); #include <stdio.h> int main() { char board[3][3]; int i; for (i=0;i<8;i++)
void selectLocation(char board[],int choice);
void displayBoard(char[]);
#include <stdio.h>
int main()
{
char board[3][3];
int i;
for (i=0;i<8;i++)
{
displayBoard(board);
selectLocation(board,i);
}
return 0;
}
void displayBoard(char board[])
{
printf(" 0 1 2");
printf("\n --- --- --- ");
printf("\n0 | | | |");
printf("\n --- --- --- ");
printf("\n1 | | | |");
printf("\n --- --- --- ");
printf("\n2 | | | |");
printf("\n --- --- --- ");
}
void selectLocation(char board[],int choice)
{
int x,y;
printf("Enter a location for X or O in x,x format");
printf("\nex. '0,1' '1,2'");
scanf("%d,%d",&x,&y);
if (choice%2==1)
{
board[x][y]='X';
}
else
{
board[x][y]='O';
}
}
void selectLocation(字符板[],int-choice);
无效显示板(字符[]);
#包括
int main()
{
炭板[3][3];
int i;
对于(i=0;i
电路板不是2D阵列,您可能会遇到该错误
board[x]
仅有效。因为您收到的是字符数组而不是2D数组。
因此,将定义和声明中函数的签名都更改为接收2D数组
void selectLocation(char board[][3],int choice)
{
int x,y;
...
及
现在显示数组类型的元素类型不完整。@BobbyII在哪个函数中?@BobbyII确定。进行更改。必须指定第二个索引大小。学习C给出正确答案,另一个问题是您没有检查scanf
的结果(如果用户键入“abc,def”,您可能会遇到问题)
void selectLocation(char board[][3],int choice)
{
int x,y;
...
void displayBoard(char board[][3])
{