gpt4 book ai didi

c - sprintf 转换说明符的使用

转载 作者:太空宇宙 更新时间:2023-11-04 01:39:03 25 4
gpt4 key购买 nike

代码如下:

static unsigned char text  [] [10] = {
"/name",
"/place",
"/address",
"/office"
};

unsigned char l_my_file[80];

main()
{
int i;
for(i = 0;i<5;i++)
{
(void)sprintf((char *)l_my_file, "%s",text[i]);
}
}

现在这个 sprintf 工作得很好,所有的字符串都正确打印了。

现在,当我运行我的质量分析检查工具时,问题来了,该工具弹出一条消息,告知参数类型与转换说明符编号 1 不匹配

sprintf 中使用的转换说明符有什么建议吗?

最佳答案

我的猜测是您的 QA 工具坚持使用 char *(而不是 unsigned char *)作为 %s 的参数。

尝试将数组声明为 char 或将 text[i] 转换为 char *

关于c - sprintf 转换说明符的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9014335/

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