gpt4 book ai didi

c - 警告在 sprintf 中使用格式字符串

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

    uint16_t foo;
char str[ 32 ];
sprintf( str, "%6u", foo )

前面的代码片段抛出警告:#181 参数与相应的格式字符串不兼容

您将如何摆脱该警告?

彼得

最佳答案

“%u”用于unsigned,而不是uint16_t。你想要这样的东西:

#include <inttypes.h>

sprintf(str, "%6" PRIu16, foo);

关于c - 警告在 sprintf 中使用格式字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20861891/

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