Get uint from hex-string in C

c, hex, string, type-conversion

Solution

unsigned int h;
sscanf(code, "%x", &h);

EDIT taking account of the remark of ExP : `%x` could catch the value in the string `"0x41"`

Problem

Let's say I have a `char*` called code, and it has `"0x41"` in it. ``` char *code = "0x41"; ``` How can I convert that into an `unsigned int`? (To be exact, I need a `WORD`, but that's just an `unsigned int`).

Original source