gpt4 book ai didi

c - int32_t 的格式字符串?

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

什么格式字符串适用于 int32_t来自 <stdint.h>

我正在尝试打印值,但我发现我应该使用:

("... %" PRId32 "...\n", value) 

来自 <inttypes.h>但我得到的只是通常的'format %d expects argument of type int, but argument 2 has type int32_t ' 消息。

#include <stdint.h>
#include <inttypes.h>

int32_t variable = 99;
printf("Value: %" PRId32 "\n", variable);

常规范式字符串不适用于它。那么我可以使用哪种格式字符串呢?

编辑1:由于有很多误解,我已经编辑了它;我已经包含了两个标题。

编辑 2:添加实际函数(省略包含和动态分配;其中的所有内容都将被分配):

struct stuff {int32_t * array[3];}

printf("Value: %" PRId32 "\n", stuff->array[0]);

编辑 3:就像那样,错误出现在完全不同的地方。 array不应该有*在它的前面。

最佳答案

我相信您误读了错误。实际错误是。

format %d expects argument of type int , but argument 2 has type int32_t *.

注意最后的*。您正在传递一个需要整数的指针。您必须这样取消引用指针:

printf("Value: %" PRId32 "\n", *stuff->array[0]);

关于c - int32_t 的格式字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43263046/

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