atoi -- Convert Character String to Integer

Format

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

Language Level: ANSI, POSIX, XPG4
atoi converts a character string to an integer value.

The input string is a sequence of characters that can be interpreted as a numerical value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number; this character can be the null character that ends the string.

atoi does not recognize decimal points nor exponents. The string argument for this function has the form:

where whitespace consists of the same characters for which the isspace function is true, such as spaces and tabs. atoi ignores leading white-space characters. digits is one or more decimal digits.

Return Value
atoi returns an int value produced by interpreting the input characters as a number. The return value is 0 if the function cannot convert the input to a value of that type. The return value is undefined in the case of an overflow.

Example
This example shows how to convert numbers stored as strings to numerical values using the atoi function.

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   int i;
   char *s;
   s = " -9885";
   i = atoi(s);                         /* i = -9885 */
   printf("atoi(\"%s\") = %d\n", s, i);
   return 0;
   /***************************************************
      The output should be:
      atoi(" -9885") = -9885
   ***************************************************/
}


atof -- Convert Character String to Float
atol -- Convert Character String to Long Integer
_atold -- Convert Character String to Long Double
strtod -- Convert Character String to Double
strtol -- Convert Character String to Long Integer
strtold -- Convert String to Long Double
<stdlib.h>