gpt4 book ai didi

c - '%s'期望参数类型为 'char *',但参数类型为 'int'

转载 作者:行者123 更新时间:2023-12-02 10:52:27 26 4
gpt4 key购买 nike

我确实看到了类似的问题,给出的解决方案是将其声明为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行中

最佳答案

函数参数board是一个char指针,因此当您尝试打印该char指针的索引时,它将在该索引中提供对char的取消引用。
因此,发生的情况是您尝试打印字符串,但变量为char。
如果要打印字符,则需要将%s更改为%c
这样,您可以从字符“数组”中的索引中打印所需的字符。

关于c - '%s'期望参数类型为 'char *',但参数类型为 'int',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64313261/

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