Format
#include <stdlib.h> long long strtoll(const char *nptr, char **endptr, int base);
Language Level: Extension
strtoll converts a character string to a long long value. The
parameter nptr points to a sequence of characters that
can be interpreted as a numerical value of type long long int.
This function stops reading the string at the first character
that it cannot recognize as part of a number. This character can
be the null character (\0) at the end of the string. The ending
character can also be the first numeric character greater than or
equal to the base.
When you use the strtoll function, nptr should point to a string with the following form:

If base is in the range of 2 through 36, it becomes the base of the number. If base is 0, the prefix determines the base (8, 16, or 10): the prefix 0 means base 8 (octal); the prefix 0x or 0X means base 16 (hexadecimal); using any other digit without a prefix means decimal.
Return Value
strtoll returns the value represented in the string,
except when the representation causes an overflow. For an
overflow, it returns LONGLONG_MAX or LONGLONG_MIN, according to
the sign of the value and errno is set to ERANGE. If base
is not a valid number, strtoll sets errno to EDOM.
errno is set to ERANGE for the exceptional cases, depending on the base of the value. If the string pointed to by nptr does not have the expected form, no conversion is performed and the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a NULL pointer.
Example
This example converts the strings to a long long value.
It prints out the converted value and the substring that stopped
the conversion.
#include <stdlib.h> #include <stdio.h>
int main(void)
{
char *string,*stopstring;
long long ll;
int bs;
string = "10110134932";
printf("string = %s\n\n", string);
for (bs = 2; bs <= 8; bs *= 2) {
ll = strtoll(string, &stopstring, bs);
printf(" strtoll = %lld (base %d)\n", ll, bs);
printf(" Scan stopped at %s\n\n", stopstring);
}
return 0;
/**************************************************
The output should be:
string = 10110134932
strtoll = 45 (base 2)
Scan stopped at 34932
strtoll = 4423 (base 4)
Scan stopped at 4932
strtoll = 2134108 (base 8)
Scan stopped at 932
**************************************************/
}
![]()
atof -- Convert Character String to Float
atoi -- Convert Character String to
Integer
atol -- Convert Character String to Long
Integer
_atold -- Convert Character String to
Long Double
_ltoa -- Convert Long Integer to String
strtod -- Convert Character String to
Double
strtol -- Convert Character String to
Long Integer
strtold -- Convert String to Long
Double
strtoul -- Convert String Segment to
Unsigned Integer
wcstod -- Convert Wide-Character
String to Double
wcstol -- Convert Wide-Character to
Long Integer
wcstoul -- Convert Wide-Character
String to Unsigned Long
<stdlib.h>