對於數組而言,我一直都會遇到下述錯誤:在selectLocation函數中,下標值既不是指針也不是矢量。這只是什麼是一個井字棋計劃的開始。我究竟做錯了什麼?既不是參數,也不是指針
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';
}
}
LearningC給你正確的答案,另一個問題是,你不檢查結果'scanf'(如果用戶輸入「abc,def」,你可能會遇到麻煩) –