1

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.

undur_gongor
  • 15,657
  • 5
  • 63
  • 75
BSalunke
  • 11,499
  • 8
  • 34
  • 68

2 Answers2

6

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.

Community
  • 1
  • 1
cnicutar
  • 178,505
  • 25
  • 365
  • 392
1
void *ptr;
sscanf(hex, "%p", &ptr);
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • Thanks R, but it give following error with the use of void: "error: `void*' is not a pointer-to-object type" – BSalunke Sep 23 '11 at 04:48