C程序字符数组错误

标签 c arrays char

所以我对数组的概念相当陌生,对函数的概念也非常陌生。现在我正在尝试创建一个包含所有“_”的 3 x 3 数组,稍后可以使用其他函数对其进行修改。这是我到目前为止的代码:

#include<stdio.h>
#define SIZE 3



void clear_table(char ary[SIZE][SIZE])
{

    for(int i = 0; i < SIZE; i++)

    {
        for( int j = 0; j < SIZE; j++)
        {
            ary[i][j] = "_";
        }

    }



}

void display_table(char ary[SIZE][SIZE])
{
for( int i = 0; i < SIZE; i++)
{
    for( int j = 0; j < SIZE; j++)
    {
        printf("%c", ary[i][j]);
    }
    printf("\n");
}

}

int main ()
{
   //Declare the tic-tac-toe board
   char board[SIZE][SIZE];
   //The row and column of the move for either player 1 or 2
   int row, col;
   //Clear the table
   clear_table(board);
   //Display the table
   display_table(board);

   return 0;
}

但是我在这段代码中遇到错误:

warning: assignment makes integer from pointer without a cast [-Wint-conversion]
    ary[i][j] = "_";

当我执行该程序时,我得到:

$$$
$$$
$$$

而不是:

_ _ _
_ _ _ 
_ _ _ 

有人可以帮我理解这个错误吗?

最佳答案

在第 14 行,您正在使用 ary[i][j] = "_";

改用ary[i][j] = '_';

最初,您分配一个字符串,而您想要一个字符

关于C程序字符数组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49479789/

相关文章:

C : static array

数组的大小可以在c中运行时确定吗?

Javascript:将与过滤谓词不匹配的元素放入单独的数组中

c++ - 将 std::array<char, 10> 的最后一个字符转换为 int

c - 一些指针澄清

C: exec到我自己的exe文件

php - 在 PHP 中拆分数组的哪个函数更有效?

c++ - 如何连接 "constant strings"和字符?

C++数组作为指针问题

java - Java中的递增字符类型