从 C 中的十六进制字符串获取 uint

äym*_*ymm 3 c string hex type-conversion

假设我有一个char*被调用的代码,它包含"0x41"在其中。

char *code = "0x41";
Run Code Online (Sandbox Code Playgroud)

我怎样才能把它转换成一个unsigned int?(确切地说,我需要一个WORD,但这只是一个unsigned int)。

MOH*_*MED 5

unsigned int h;
sscanf(code, "%x", &h);
Run Code Online (Sandbox Code Playgroud)

编辑考虑到ExP的评论:%x可以捕获字符串中的值"0x41"