BSalunke
BSalunke

Reputation: 11727

How to convert an address stored in char array to actual address?

I have following char array:

char hex[16] = "0x7fffa410c240"

How can i convert it into numerical address that can be assigned to another variable. Important is that i have to keep the base of value remaining the same i.e. 16 (hexadecimal). Thanks in advance.

Upvotes: 1

Views: 252

Answers (2)

cnicutar
cnicutar

Reputation: 182619

Try the function strtoull which returns unsigned long long.

On Visual Studio strtoull is not available, but _strtoui64 can probably be used.

EDIT

As R.. mentions in the comments you should probably use sscanf(hex, "%p", ..) or strtoumax which has the same prototype as strtoull but returns an uintmax_t.

Upvotes: 6

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215201

void *ptr;
sscanf(hex, "%p", &ptr);

Upvotes: 1

Related Questions