我确实看到了类似的问题,给出的解决方案是将其声明为char数组而不是char。我这样做了,但仍然看到错误。
我的代码当前为:
#include <stdio.h>
char ticTacToeBoard(char board[11])
{
printf("%s %s %s %s %s", board[0], board[10], board[1], board[10], board[2]);
}
int main()
{
char board[11] = {' ',' ',' ',' ',' ',' ',' ',' ',' ','__','|'};
ticTacToeBoard(board);
return 0;
}
错误在代码的printf行中
答案 0 :(得分:1)
函数参数board
是一个char指针,因此当您尝试打印该char指针的索引时,它将在该索引中取消对char的引用。
因此,发生的情况是您尝试打印字符串,但变量为char。
如果要打印字符,则需要将%s
更改为%c
。
这样,您可以从字符的“数组”中的索引中打印所需的字符。