uint64_t

Hello to all,

I have a uint64_t variable and when I do:

1
2
3
4
5
uint64_t it = 100;

char msgname[2000];
sprintf(msgname, "Transport:%d+%d-", it, outGateBaseId+i);


It appears to have a format error because of uint64_t. Instead of %d I have already tried %i, %ll but without success.

Can someone advise me.

Regards
CMarco
Try %u for unsigned int, not sure if works with long long, which is what uint64_t is (if not, just long)
Use stringstreams. Then you won't have to worry about that kind of stuff anymore, at all.
1
2
3
uint64_t it = 100;
stringstream msgname;
msgname<<"Transport:"<<it<<'+'<<outGateBaseId+i;
1
2
uint64_t i = 5;
printf ( "% PRIu64 ", i ) ;


and for that you have to include
#include <inttypes.h>
I wasn't sure whether the OP's code had to be C.
Have you tried %lu or %llu?

Or maybe this will work:
sprintf(msgname, "Transport:%"PRIu64"+%d-", it, outGateBaseId+i);
Or simply use stringstreams and forget about all the trouble!
Hello

Thanks to all for the tips.

With the include and %llu the problem was solved.
The stringstreams solutions solve this also.

Regards
In C++ type name uint64_t is declared in header <cstdint> and is usually a typedef for unsigned long long. So you can use format specifier ll
From the C Standard

ll (ell-ell) Specifies that a following d, i, o, u, x, or X conversion specifier applies to a long long int or unsigned long long int argument; or that a
following n conversion specifier applies to a pointer to a long long int
argument.
uint64_t is unsigned long on one of the production systems at my work. PRIu64 is the right solution, for C.
Topic archived. No new replies allowed.