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

标签 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);
}

这些是我更改主板的唯一地方,我不认为这里有任何错误,但我将它们仅供引用。

最佳答案

根据你的变量名称,我注意到你的主板有一个 NxN 矩阵。但是你的移动历史记录是一个大小为 N 的数组。这可能是问题所在吗?

关于c - 如何停止用替换字符 � 替换字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56314782/

相关文章:

python - UnicodeEncodeError : 'ascii' codec can't encode character at special name

python - Google App Engine TextProperty 和 UTF-8 : When to Encode/Decode

c - 两个三位数的最大回文积

c - NodeJS 退出代码左移 8 位

c - fork () 和 execlp () , execlp() 之前的 printf 没有被执行

C 输入的 char 返回不同的 char

c - 在 C 中立即(逐个数据包)从套接字接收 TCP 有效负载

javascript - 在占位符 JSX 中渲染特殊字符

python - Python 中波兰语字符的 Unicode 编码

xml - XML 名称中是否允许增补字符?