gpt4 book ai didi

c - 如何转换 const char 字符串中的 uint64_t 值?

转载 作者:太空狗 更新时间:2023-10-29 14:50:28 24 4
gpt4 key购买 nike

看一种情况

uint64_t trackuid = 2906622092;

现在我想在一个函数中传递这个值,函数参数是 const char*

func(const char *uid)
{
printf("uid is %s",uid);
}

这应该打印

uid is 2906622092 

我该怎么做?

最佳答案

// length of 2**64 - 1, +1 for nul.
char buff[21];

// copy to buffer
sprintf(buff, "%" PRIu64, trackuid);

// call function
func(buff);

这需要 C99,但是,我的内存表明 MS 编译器没有 PRIu64。 (PRIu64inttypes.h 中。)YMMV。

关于c - 如何转换 const char 字符串中的 uint64_t 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8323159/

24 4 0
文章推荐: html - 如何仅使用
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com