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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.