int  atoi ( const char * string );

Convert string to integer.
  Parses string interpreting its content as a number and returns an int value.


String representing an integer number. The number is considered until a non-numeric character is found (digits, and signs are considered valid numeric characters for this parameter as specified in format). The format used is:
(where whitespaces are any tab or space character and nnnnn may be any number of digits)

Return Value.
  The converted integer value of the input string.
  On overflow the result is undefined.
  If an error occurs 0 is returned.

  Defined in ANSI-C.


/* atoi example */
#include <stdio.h>
#include <stdlib.h>

main ()
  int i;
  char szInput [256];
  printf ("Enter a number: ");
  gets ( szInput );
  i = atoi (szInput);
  printf ("Value entered is %d, and its double %d",i,i*2);
  return 0;
Enter a number: 73
Value entered is 73, and its double 146

See also.
  atof, atol, ecvt, fcvt, gcvt, strtod

© The C++ Resources Network, 2000