Dhayalan Pro
Dhayalan Pro

Reputation: 579

Retrieving an address stored as a string

I have a string

char value[16]="ffffffffc06e91"

and I need to retrieve the address stored as a string in the variable value.

ie..

void * ptr = NULL;
somefunction(value,ptr); // ptr = 0xffffffffc06e91

Is there such a function or a method to do so ?

Thanks

Upvotes: 0

Views: 23

Answers (2)

Dhayalan Pro
Dhayalan Pro

Reputation: 579

We could use strtol to accomplish this, thanks to @Bwebb for pointing out atoi which led me to strtol.

void * ptr = (void*)(long)strtol(value,NULL,16);

Upvotes: 0

r3mainer
r3mainer

Reputation: 24557

Don't use atoi(); an int value probably isn't big enough to store this value, and the function won't work with hexadecimal strings.

Use strtoll() instead:

void *ptr = (void*)strtoll("ffffffffc06e91", NULL, 16);

Upvotes: 1

Related Questions