strtoll() — Convert String to Signed Long Long
Format
#include <stdlib.h>
long long strtoll(const char * __restrict__ nptr,
char ** __restrict__ endptr, int base);
General Description
The strtoll() function converts nptr, a character string, to a signed long long value.
The function decomposes the entire string into three parts:
- A sequence of white space characters as defined by the IBM®-1047 codepage.
- A sequence of characters interpreted as an unsigned integer in some base notation. This is the subject sequence.
- A sequence of unrecognized characters.
- 10
- Sequence starts with nonzero decimal digit.
- 8
- Sequence starts with 0, followed by a sequence of digits with values from 0 to 7.
- 16
- Sequence starts with either 0x or 0X, followed by digits, and letters A through F or a through f.
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.
Returned Value
If successful, strtoll() returns the converted signed long long value, represented in the string.
If unsuccessful, strtoll() returns 0 if no conversion could be performed. If the correct value is outside the range of representable values, strtoll() returns LLONG_MAX (LONGLONG_MAX) or LLONG_MIN (LONGLONG_MIN), according to the sign of the value. If the value of base is not supported, strtoll() returns 0.