So I recently I had to take a hex address stored in a string and convert it back to a pointer in C++. So it basically had to go from this
string address = "0X...abab123a"
char *address = ?
I’ve never had to do that before so I wasn’t really sure if it was even possible. It turns out it is. You do so like this.
string strAddress = "0x...abab12" void *pAddresss = (void *)std:stoul(strAddress.c_str(), 0, 16);
then later you can cast the pAddress back to char *, like this:
char *chAddress = (char *)pAddress.
Assuming that this address actually exists in your application you can actually do something with it.
This code is for C++ and the address we had in the string was a valid address, not just a random hex value.
If you need to do this in C just skip the use of string and std:stoul. Instead, use strtol.
Until next time. Keep coding.