long int strtol(const char *str, char **endptr, int base);

The string pointed to by the argument str is converted to a long integer (type long int). Any initial whitespace characters are skipped (space, tab, carriage return, new line, vertical tab, or formfeed). The number may consist of an optional sign and a string of digits. Conversion stops when the first unrecognized character is reached.

If the base (radix) argument is zero, then the conversion is dependent on the first two characters. If the first character is a digit from 1 to 9, then it is base 10. If the first digit is a zero and the second digit is a digit from 1 to 7, then it is base 8 (octal). If the first digit is a zero and the second character is an x or X, then it is base 16 (hexadecimal).

If the base argument is from 2 to 36, then that base (radix) is used and any characters that fall outside of that base definition are considered unconvertible. For base 11 to 36, the characters A to Z (or a to z) are used. If the base is 16, then the characters 0x or 0X may precede the number.

The argument endptr is a pointer to a pointer. The address of the character that stopped the scan is stored in the pointer that endptr points to.

On success the converted number is returned. If no conversion can be made, zero is returned. If the value is out of the range of the type long int, then LONG_MAX or LONG_MIN is returned with the sign of the correct value and ERANGE is stored in the variable errno.