strtoi
Converts an ASCII string to an integer
#include <stdlib.h> int strtoi ( const char *str, int base);
strtoi returns the integer value for the input ASCII string and base. This value is inaccurate if a value in str is outside the range of the value specified in base. If a character in p is encountered outside the range of base, the function returns the value computed up to that point.
The base parameter can be 0, in which case base is given one of the following values:
#include <stdlib.h> main() { int decimal_value; int hex_value; decimal_value = strtoi( "1234567", 10 ); /* decimal_value is printed as: 1234567 */ printf( "decimal_value = %d\n", decimal_value ); decimal_value = strtoi ("123a4567\n", 10); /* decimal_value is printed as: 123 */ printf ("decimal_value = %d\n", decimal_value ); hex_value = strtoi ("abc123", 16); /* hex_value is printed as: abc123 */ printf ("hex_value = %x\n", hex_valu ); hex_value = strtoi ("abch123", 16); /* hex_value is printed as: abc */ printf ("hex_value = %x\n", hex_value); }