Name

atoi - converts a string to an integer

Library

libc.lib

Synopsis

  #include <stdlib.h>
  int atoi (const char *nptr);

Return values

The atoi function returns the converted value if the value can be represented.

Detailed description

The atoi function converts the initial portion of the string pointed to by nptr to int representation.

It is equivalent to:

(int)strtol(nptr, (char **)NULL, 10);

         


Examples

#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
  /* call to atoi */
  char *str = "  -56957jdhfjk";    
  int i = atoi( str );
  printf( "result of atoi: %d\n", i );
}

         

Output

result of atoi: -56957

         


Implementation notes

The atoi function is not thread-safe and also not async-cancel safe.

The atoi function has been deprecated by strtol and its use is not preferred.


Errors

No errors are defined.

See also

atof, atol, strtod, strtol, strtoul

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top