c - 二维数组上的位置 0 0 不保存整数

标签 c

这是我在 stackoverflow 上的第一篇文章。我的程序出现了问题,我的老师不知道发生了什么,他建议向 stackoverflow 询问(你应该得到他的薪水)。 嗯,这是我的代码:

#include <stdio.h>

#define MAX_X 3
#define MAX_Y 3
#define SYMBOL_X "X"
#define SYMBOL_Y "Y"
#define SYMBOL_EMPTY -1
#define FALSE 0
#define TRUE 1

void printBoard(int board[MAX_X][MAX_Y]){
    printf("\n");
    printf("%d\t%d\t%d\n",board[0][0],board[1][0],board[2][0]);
    printf("\n");
    printf("%d\t%d\t%d\n",board[0][1],board[1][1],board[2][1]);
    printf("\n");
    printf("%d\t%d\t%d\n",board[0][2],board[1][2],board[2][2]);
    printf("\n");
}
void fillboard(int board[MAX_X][MAX_Y]){
    int i,j;
    for (i = 0; i < MAX_Y; ++i){
        for (j = 0; j < MAX_X; ++j){
            board[j][i]=SYMBOL_EMPTY;
        }
    }
}
int findEmptyBox(int board[MAX_X][MAX_Y])
{
    int i,j;
    for (i = 0; i < MAX_Y; ++i){
        for (j = 0; j < MAX_X; ++j){
            if(board[j][i]=SYMBOL_EMPTY)return FALSE;
        }
    }
    return TRUE;
}
int checkBoxIntroduced(int x,int y){
    if((x!=0 && x!=1 && x!=2) || (y!=0 && y!=1 && y!=2)){
        printf("Alguna de las casillas no ha sido introducida correctamente\n");
        return FALSE;
    }
    return TRUE;
}
void introducirFichaConDialogos(int board[MAX_X][MAX_Y],int player){
    int x,y;
    do{
    printf("Introduce la posicion X: \n");
    scanf("%d",&x);
    printf("Introduce la posicion Y: \n");
    scanf("%d",&y);
    }while(!checkBoxIntroduced(x,y));
    if(player==0)board[x][y]=1;
    else board[x][y]=2;
}
void checkPlayer(int *pplayer){
    if(*pplayer==1)*pplayer=0;
    else *pplayer=1;
}
void main(){
    int x=0,y=0,board[MAX_X][MAX_Y],i,j,player=0;
    fillboard(board);
    do{
        system("clear");
        printBoard(board);
        introducirFichaConDialogos(board,player);
        checkPlayer(&player);
    }while(!findEmptyBox(board));
}

我的问题是只有 board[0][0] 不保存符号,我和我的老师不知道发生了什么以及为什么位置只有 0 0。 感谢您的帮助,如果有人提供建议和建议,我将不胜感激。

最佳答案

数组确实保存了值

if(board[j][i]=SYMBOL_EMPTY)return FALSE;

并且只有 board[0][0] 受到影响,因为 SYMBOL_EMPTY 不为零,因此控件将从函数返回。

你的意思是比较而不是作业吗?例如

if(board[j][i]==SYMBOL_EMPTY)return FALSE;

关于c - 二维数组上的位置 0 0 不保存整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36627683/

相关文章:

C 初学者,指针和取消引用

c - 定义#define宏

c - 将信号作为错误处理

c - 在 C 中使用结构体作为输入的语法

无法在 Eclipse 中使用 gcc -shared 找到库来构建 dll

c - 在c源代码中使用dll的效率

c - *( char** ) 实现什么类型的转换?

使用 C 中的 fscanf() 将 uint8 复制到矩阵中

c - gdb 不接受用户输入

在 C 中使用较少数量的参数调用函数?