strtoll - C stdlib.h

C examples for stdlib.h:strtoll

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert string to long long integer and return as a value of type long long int.

Prototype

long long int strtoll (const char* str, char** endptr, int base);

Parameters

Parameter Description
str C-string representation of an integral number.
endptr type char* set by the function to the next character in str after the numerical value.
base Numerical base (radix)

Return Value

On success, the function returns the converted integral number as a long int value.

For non valid conversion, a zero value is returned (0LL).

For out of the range values, the function returns LLONG_MAX or LLONG_MIN (defined in <climits>), and errno is set to ERANGE.

Demo Code


#include <stdio.h>
#include <stdlib.h>

int main ()/*  ww w  . j  av  a2  s. com*/
{
  char str[] = "1234567895 17b00a12b -01010101010101010101010101010 0x6fffff";
  char* pEnd;

  long long int lli1, lli2, lli3, lli4;

  lli1 = strtoll (str, &pEnd, 10);

  lli2 = strtoll (pEnd, &pEnd, 16);

  lli3 = strtoll (pEnd, &pEnd, 2);

  lli4 = strtoll (pEnd, NULL, 0);

  printf ("%lld, %lld, %lld and %lld.\n", lli1, lli2, lli3, lli4);

  return 0;
}

Related Tutorials