#include <stdio.h>
#include <string.h>//memset
#include <stdlib.h>//free
#include <stddef.h>
#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long
int main()
{
uint64_t a=0XFFFFFFFF;
char p[16]={0};
printf("uint64_t a -10- ==%lu\r\n",a);
sprintf(p,"%lu",a);
printf("string: == %s\r\n",p);
}
上面 仅仅替换 uint64_t a=0XFFFFFFFFFFFFFFFF;
结果输出还是一样 也就是lu已经达到上限 也就是上面不行!!!!
怎么办??
sprintf(p,"%llu",a);
#include <stdio.h>
#include <string.h>//memset
#include <stdlib.h>//free
#include <stddef.h>
#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long
int main()
{
uint64_t a=0XFFFFFFFFFFFFFFFF;
char p[16]={0};
printf("uint64_t a -10- ==%llu\r\n",a);
sprintf(p,"%llu",a);
printf("string: == %s\r\n",p);
}
修改 printf("string: == %16s\r\n",p); 此时效果一样
修改 printf("string: == %.16s\r\n",p);此时可以阶段字符串
uint64_t a -10- ==18446744073709551615
string: == 1844674407370955