I have converted uint64_t
to unsigned char*
using the following:
uint64_t in;
unsigned char *out;
sprintf(out,"%" PRIu64, in);
Now I want to do the reverse. Any idea?
The direct analogue to what you're doing with sprintf(3)
would be to use sscanf(3)
:
unsigned char *in;
uint64_t out;
sscanf(in, "%" SCNu64, &out);
But probably strtoull(3)
will be easier and better at error handling:
out = strtoull(in, NULL, 0);
(This answer assumes in
really points to something, analogous to how out
has to point to something in your example code.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With