I tried using atoi function to do this, but it didn't work.
I want to convert a string that says "0x44" to an integer (as 0x44 or its decimal equivalent).
Does anyone know of an开发者_Go百科y functions that could do that?
Yes. Use strtol
instead, and specify 0 as the base.
I think this is what you are looking for...
#include<stdio.h>
#include<stdlib.h>
void main() {
char* hex = "0x44";
int i;
sscanf( hex, "%x", &i );
printf("%d\n", i);
}
精彩评论