如何停止用替换字符替换字符�?

时间:2019-05-26 15:18:12

标签: c unicode

我正在写一个带有其他功能的井字游戏。

有时,当我尝试打印字符数组(即棋盘)时,它会用带有白色问号(...)的黑色菱形或一个空的方形框替换某些字符。

我需要怎么做才能解决这个问题?

void print_board(char board[N][N], int n)
{
    printf("\nCurrent board:\n");

    for (int i = 0; i < n; i++)
    {
        printf("|");

        for (int j = 0; j < n; j++)
        {
            printf("%c|", board[i][j]);
        }

        printf("\n");
    }

    printf("\n");
}

我希望一个带有x和o的普通电路板,但是其中一些会被替换为�或一个空框。

void change_board(char board[N][N], int moves_history[TWO][N], int row, int column, int player_index, int turns_num, int board_size)
{
    char player_sign = (player_index == FIRST_PLAYER) ? FIRST_PLAYER_SIGN : SECOND_PLAYER_SIGN;
    board[row][column] = player_sign;
    moves_history[0][turns_num-1] = row;
    moves_history[1][turns_num-1] = column;
    print_board(board, board_size);

    if (did_anyone_win(board,player_index, player_sign,board_size,row,column))
    {
        exit(0);
    }

    player_index = (player_index == FIRST_PLAYER) ? SECOND_PLAYER : FIRST_PLAYER;
    player_turn(board,board_size,turns_num,player_index,moves_history);
}

void Undo(char board[N][N], int moves_history[TWO][N], int undo, int board_size, int turns_num, int player_index)
{
    for (int i = turns_num-TWO; i >= turns_num+undo-1; i--)
    {
        board[moves_history[0][i]][moves_history[1][i]] = EMPTY_CELL;
        moves_history[0][i] = 0;
        moves_history[1][i] = 0;
    }

    print_board(board,board_size);

    player_index = player_index == FIRST_PLAYER ? SECOND_PLAYER : FIRST_PLAYER;
    player_turn(board,board_size,turns_num+undo-1,player_index,moves_history);
}

这些是我更换板子的唯一地方,我认为这里没有任何错误,但我只供参考。

1 个答案:

答案 0 :(得分:0)

对不起。我的声誉不足,无法发表评论。但是我注意到,根据您的变量名,您的电路板具有NxN矩阵。但是您的移动历史记录是一个大小为N的数组。这可能是问题所在吗?