Everything

strtol


Converts a number-representing string to a long type integer.

[Format]

#include <stdlib.h>

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

[Parameters]

nptr Pointer to a number-representing string to be converted

endptr Pointer to the storage area containing a pointer to the first character that does not represent an integer

base Radix of conversion (0 or 2 to 36)

[Return values]

Normal: If the string pointed by nptr begins with a character that does not represent an integer: 0

If the string pointed by nptr begins with a character that represents an integer: Converted data as a long type integer

Abnormal: If the converted data overflows: LONG_MAX or LONG_MIN depending on the sign of the string before conversion

[Remarks]

If the converted result overflows, errno is set.

The strtol function converts data, from the first digit up to the character before the first character that does not represent an integer, into a long type integer.

In the storage area pointed by endptr, the function sets up a pointer to the first character that does not represent an integer. If some characters that do not represent an integer come before the first digit, the value of nptr is set in this area. If endptr is NULL, nothing is set in this area.

If the value of base is 0, the rules described in section 3.1.3 (4), Integers, are observed at conversion. If the value of base is 2 to 36, it indicates the radix of conversion, where a (or A) to z (or Z) in the string to be converted correspond to numbers 10 to 35. If a character that is not smaller than the base value is found in the string to be converted, conversion stops immediately. A 0 after a sign is ignored at conversion. Similarly, 0x (or 0X) is ignored when base is 16.