long strtol(const char* nptr, char** endptr, int base)


Pointer to the string containing the value to convert.
Optional storage space for output by this function.
The numerical base of the number, anything from 2 upto and including 36 or zero.


The converted value from the string.


This function will convert a string to a long value.
The string is expected to have optional leading white space followed by an optional plus (+) or minus (-) character and any number of digits.
If base is set to 16 (hexadecimal), the string may begin with an optional '0x' prefix.
If base is set to 0, the string will be parsed as having base 10 (decimal) unless it starts with '0x', in which case is is parsed as having base 16 (hexadecimal), or '0', in which case it is parsed as having base 8 (octal). This allows this function to parse C-style numbers.
If endptr is not NULL, a pointer to the next character after the parsed portion of the string is stored in the memory location reference by endptr.
If the resultant value would overflow the boundaries of the long datatype, the maximum possible value is returned. If an underflow would occur, zero will be returned. In both cases an errorcode will be set which can be queried.

Also see

strtod, strtoul


Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.