-2
我正在製作一個跳棋遊戲,其中我想將字符'x'和'o'打印到二維數組中。但我的代碼不起作用,它會打印出不同的字符。我需要幫助。將字符分配到二維數組中[棋盤格]
這裏是我的代碼:
#include <stdio.h>
void message()
{
char name[20],name2[20];
printf("Please enter the name for the first player : ");
scanf("%s", &name);
printf("Please enter the name for the second player : ");
scanf("%s", &name2);
printf("\nGood day %s and %s, let's start the game....all the best!!!\n\n", name, name2);
}
int gameboard(char board[8][8])
{
int x, y;
for(x=0; x<8; x++)
{
for(y=0; y<8; y++)
{
printf("|%c ");
}
printf("|\n\n");
}
}
void character(char board[8][8])
{
int i,j;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
if(i<3){
if(i%2 == 0){
if(j%2 == 0){
board[i][j] = ' ';
}
if(j%2==1){
board[i][j]= 'O';
}
}
if(i%2 == 1){
if(j%2 == 0){
board[i][j] = 'O';
}
if(j%2 ==1){
board[i][j]= ' ';
}
}
}
if((i==3) || (i==4))
{board[i][j] = ' ';}
if(i>4)
{
if(i%2 == 0){
if(j%2 == 0){
board[i][j] = ' ';
}
if(j%2 ==1){
board[i][j]= 'X';
}
}
if(i%2 == 1){
if(j%2 == 0){
board[i][j] = 'X';
}
if(j%2 ==1){
board[i][j]= ' ';
}
}
}
}
}
}
int main()
{
int x, y;
char bx[8][8];
message();
gameboard(bx);
character(bx);
return 0;
}
http://stackoverflow.com/a/40216407/971127 – BLUEPIXY
@XxY:註釋似乎有一些有用的代碼。請看看這個。 – CyprUS