开发者

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

开发者 https://www.devze.com 2023-04-06 21:36 出处:网络
I have following char array: char hex[16] = \"0x7fffa410c240\" How can i convert it into numerical address that can be assigned to another variable.

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. 1开发者_如何学C6 (hexadecimal). Thanks in advance.


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消