strtoll() — Convert String to Signed Long Long

Format

#include <stdlib.h>

long long strtoll(const char * __restrict__ nptr, 
char ** __restrict__ endptr, int base);
Compile Requirement: Use of this function requires the long long data type. See z/OS XL C/C++ Language Reference for information about how to make long long available.

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:

  1. A sequence of white space characters as defined by the IBM-1047 codepage.
  2. A sequence of characters interpreted as an unsigned integer in some base notation. This is the subject sequence.
  3. A sequence of unrecognized characters.
The base notation is determined by base, if base is greater than zero. If base is zero, the base notation is determined by the format of the sequence of characters that follow an optional plus or optional minus sign.
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.

When you are using strtoll(), nptr should point to a string with the following form:
Read syntax diagramSkip visual syntax diagram
>>-+-------------+--+-----+--+----+--+--------+----------------><
   '-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.

Related Information