#include <stdlib.h>
long int strtol(const char * __restrict__nptr,
char ** __restrict__endptr, int base);
The strtol() function converts nptr, a character string, to a long int value.
The function decomposes the entire string into three parts:
If the base is greater than zero, the subject sequence contains decimal digits and letters, possibly preceded by either a plus or a minus sign. The letters a (or A) through z (or Z) represent values from 10 through 36, but only those letters whose value is less than the value of the base are allowed.
>>-+-------------+--+-----+--+----+--+--------+---------------->< '-white space-' +- + -+ +-0--+ '-digits-' '- - -' +-0x-+ '-0X-'
The pointer to the converted characters, even if conversion was unsuccessful, is stored in the object pointed to by endptr, if endptr is not a NULL pointer.
If successful, strtol() returns the converted long int value.
If unsuccessful, strtol() returns 0 if no conversion could be performed. If the correct value is outside the range of representable values, strtol() returns LONG_MAX or LONG_MIN, according to the sign of the value. If the value of base is not supported, strtol() returns 0.