atol - C stdlib.h

C examples for stdlib.h:atol

Type

function

From


<cstdlib>
<stdlib.h>

Description

Convert string to long integer

Prototype

long int atol ( const char * str );

Parameters

Parameter Description
str C-string representation of an integral number.

Return Value

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

For non valid conversion, a zero value is returned.

Demo Code


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

int main ()/*from   ww  w  .  ja  v a 2s  .  c om*/
{
  long int li;
  char buffer[256];

  printf ("Enter a long number: ");

  fgets (buffer, 256, stdin);

  li = atol(buffer);

  printf ("The value entered is %ld. Its double is %ld.\n",li,li*2);

  printf ("%ld.\n", atol("0"));
  printf ("%ld.\n", atol("111111110"));

  printf ("%ld.\n", atol("q"));
  return 0;
}

Related Tutorials