How do you format an unsigned long long int using printf?
%d
--> for int
%u
--> for unsigned int
%ld
--> for long int
or long
%lu
--> for unsigned long int
or long unsigned int
or unsigned long
%lld
--> for long long int
or long long
%llu
--> for unsigned long long int
or unsigned long long
For long long (or __int64) using MSVS, you should use %I64d:
__int64 a;
time_t b;
...
fprintf(outFile,"%I64d,%I64d\n",a,b); //I is capital i
You may want to try using the inttypes.h library that gives you types such as
int32_t
, int64_t
, uint64_t
etc.
You can then use its macros such as:
uint64_t x;
uint32_t y;
printf("x: %"PRId64", y: %"PRId32"\n", x, y);
This is "guaranteed" to not give you the same trouble as long
, unsigned long long
etc, since you don't have to guess how many bits are in each data type.
Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).
printf("%llu", 285212672);