gpt4 book ai didi

使用 sprintf 将 long int 转换为 ASCII

转载 作者:行者123 更新时间:2023-11-30 17:20:42 25 4
gpt4 key购买 nike

我想使用 sprintf 将长整数转换为 ASCII 值,例如,如果 long int val = 40000,我使用

sprintf(buff, "%ld", val);
printf(%s\n", buff);

它只打印 d,而不是 40000。 如果我改为 unsigned long,

sprintf(buff, "%lu", val);
printf(%s\n", buff);

它只打印你。编译器/工具链有问题吗?

最佳答案

您可以引用this

void UlToStr(char *s, unsigned long bin, unsigned char n)
{
s += n;
*s = '\0';

while (n--)
{
*--s = (bin % 10) + '0';
bin /= 10;
}
}

关于使用 sprintf 将 long int 转换为 ASCII,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28470516/

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