gpt4 book ai didi

c - 打印命令给出功能错误

转载 作者:行者123 更新时间:2023-11-30 18:24:13 25 4
gpt4 key购买 nike

void print( matrix)
{
printf(" 0 1 2 3 4 5 6 7 \n"); /* printing the game board */
printf(" ------------------------------------- \n");
for (int i = 0; i < 8; i++)
{
printf("%d|", i);
for (int j = 0; j < 8; j++)
{
printf(" %3c ", matrix[i][j]);
}
printf("\n");
}
}

所以我在编译器中定义了这个函数,运行代码并得到了该行的以下错误消息 printf("%3c ",matrix[i][j]);

subscripted value is neither array nor pointer nor vector

我尝试将matrix定义为int和char值,但仍然出现相同的错误

我想通过调用函数来实现什么
enter image description here

还有一件事是,代码本身不是函数,也可以正常工作

调用函数:首先我定义了

char playboard[8][8];

然后用符号“~”填充数组

for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
playboard[i][j] = '~';
}
}

然后调用函数 print

print(playboard);

最佳答案

您可能想要这个:

void print(char matrix[8][8])
{
printf(" 0 1 2 3 4 5 6 7\n"); /* printing the game board */
printf(" -------------------------------------\n");
for (int i = 0; i < 8; i++)
{
printf("%d|", i);
for (int j = 0; j < 8; j++)
{
printf(" %3c ", matrix[i][j]);
}

printf("\n");
}
}

关于c - 打印命令给出功能错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43325138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com