I have a question, does anybody know about a function in C that will convert a char string like '2C' into a decimal number.
Thanks.
I have a question, does anybody know about a function in C that will convert a char string like '2C' into a decimal number.
Thanks.
>does anybody know about a function in C that will convert a char string like '2C' into a decimal number.
sscanf() or strtol(), take your pick.
Code:#include <stdlib.h> #include <stdio.h> . . int num; if (sscanf("2C", "%X", &num) != 1) { printf("Error during conversion.\n"); return EXIT_FAILURE; }
An easier method is to use "strtol". It allows you to use any base you like, up to (I think) 36.
Edit: Swoopy beat me to it.
--
Mats
Thanks guys!!!!