Name

atol, atoll
- convert a string to an integer ASCII string to long or long long integer

Library

libc.lib

Synopsis

  #include <stdlib.h>
  long atol (const char *nptr);
  long long atoll (const char *nptr);

Return values

The atol and atoll functions return the converted value if the value can be represented.

Detailed description

The atol function converts the initial portion of the string pointed to by nptr to long integer representation.

It is equivalent to:

     strtol(nptr, (char **)NULL, 10);
The atoll function converts the initial portion of the string pointed to by nptr to long long integer representation. It is equivalent to:
     strtoll(nptr, (char **)NULL, 10);

Examples

#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
 /* call to atol */
 long l = atol( "-000002344" );
 
 printf( "result of atol: %ld\n", l );
}

         

Output

result of atol: -2344

         

#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
 /* call to atoll */
 long long l = atoll("454756356bs");
 
 printf( "result of atoll: %ld\n", l );
}

         

Output

result of atoll: 454756356

         

Errors

No errors are defined.

See also

atof, atoi, strtod, strtol, strtoul

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top