所以我对数组的概念相当陌生,对函数的概念也非常陌生。现在我正在尝试创建一个包含所有“_”的 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/