(ANSI Standard)
#include <stdlib.h> li = strtol( s, p, base );
#include <stdlib.h> ... char *p, *s; long li; ... s = "20y"; li = strtol(s,&p,0); /* * At this point, "p" will point at the character 'y' * in the string constant, and "li" would have the * value 20 */ li = strtol(s,NULL,10); /* assigns 20 to li */ li = strtol(s,NULL,8); /* assigns 16 to li */
"strtol" converts the string "s" into a long integer. Conversion stops with the first character that cannot be part of such a number.
The string to be converted can contain the digits '0' to '9'. Depending on the base, the string can also contain letters representing digits greater than 9. The best known example is hexadecimal which uses '0' to '9' and 'A' to 'F' as digits. An upper case letter has the same value as a lower case one, so "abc" is the same number as "ABC".
Since you have 10 possible digits and 26 letters, the maximum value for the "base" argument is 36.
Copyright © 1996, Thinkage Ltd.