我尝试将无符号的long long转换为字符串,如下所示
unsigned long long Data = 12;
char Str[20];
sprintf(Str, "%lld",Data);当我想看,但我总是看到00
Str[0],Str[1]....;怎么了!
发布于 2010-10-18 19:02:42
在大多数情况下,%llu应该可以做到这一点。但在某些视窗平台上,你可能不得不使用%I64u。
发布于 2010-10-18 19:02:54
%lld用于签名的long long,请改用%llu。
发布于 2013-03-03 10:59:19
%llu应该可以按照添加到标准中的方式工作。但是,您可以使用安全版本的snprintf,或者考虑编写自己的函数,而不是snprintf。这里有一个你可能会感兴趣的。
char *ulltostr(uint64 value, char *ptr, int base)
{
uint64 t = 0, res = 0;
uint64 tmp = value;
int count = 0;
if (NULL == ptr)
{
return NULL;
}
if (tmp == 0)
{
count++;
}
while(tmp > 0)
{
tmp = tmp/base;
count++;
}
ptr += count;
*ptr = '\0';
do
{
res = value - base * (t = value / base);
if (res < 10)
{
* --ptr = '0' + res;
}
else if ((res >= 10) && (res < 16))
{
* -- ptr = 'A' - 10 + res;
}
} while ((value = t) != 0);
return(ptr);
}https://stackoverflow.com/questions/3958449
复制相似问题