我想與兩名玩家進行一次tic tac toe遊戲。我很遠,它的大部分工作。我無法弄清楚如何打印出存儲在數組中的字符串。我看過很多循環作爲例子。請讓我知道最新消息。TicTacToe打印贏家
輸入代碼在這裏
int main()
{ time_t t;
char player1 [23];
char player2 [23];
int Let;
int Turns = 0;
printf("\n Welcome to Galactic Tic Tac Toe:\n");
printf("\n Please enter player 1's name");
fgets(player1, 22, stdin);
printf("\nPlayer 2's name?\n");
fgets(player2, 22, stdin);
void winner (char board [][9], char player1 [][23], char player2 [][23]){
if (board [0][0] && board [0][1] && board [0][2] == 'X'){printf("\nPlayer 1 has won\n Congratulations : %s ", player1);}
if (board [0][3] && board [0][4] && board [0][5] == 'X'){printf("\nPlayer 1 has won\n Congratulations : %s ", player1);}
if (board [0][6] && board [0][7] && board [0][8] == 'X'){printf("\nPlayer 1 has won\n Congratulations : %s ", player1);}
if (board [0][0] && board [0][1] && board [0][2] == 'O'){printf("\nPlayer 2 has won\n Congratulations : %s ", player2);}
if (board [0][3] && board [0][4] && board [0][5] == 'O'){printf("\nPlayer 2 has won\n Congratulations : %s ", player2);}
if (board [0][6] && board [0][7] && board [0][8] == 'O'){printf("\nPlayer 2 has won\n Congratulations : %s ", player2);}
if (board [0][0] && board [0][5] && board [0][8] == 'X'){printf("\nPlayer 1 has won\n Congratulations : %s ", player1);}
if (board [0][2] && board [0][5] && board [0][7] == 'X'){printf("\nPlayer 1 has won\n Congratulations : %s ", player1);}
if (board [0][0] && board [0][5] && board [0][8] == 'O'){printf("\nPlayer 1 has won\n Congratulations : %s ", player2);}
if (board [0][2] && board [0][5] && board [0][7] == 'O'){printf("\nPlayer 1 has won\n Congratulations : %s ", player2);}
}
我可以添加開始代碼以及幫助。老實說,我始終沒有真正理解打印循環以及爲什麼它們通常用於數組。 – user3769362
對不起,就像我說的全新的,我剛剛發佈它,我想我搞砸了初始化...也許 – user3769362