atoi
raw OCR
Converts a string to an integer.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
int atoi(const char *s);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
atoi converts a string pointed to by s to int; atoi recognizes (in the following order)
u an optional string of tabs and spaces B an optional sign a a string of digits
The characters must match this generic format:
[zvs] [sn] [ddd]
In this function, the first unrecognized character ends the conversion.
There are no provisions for overflow in atoi (results are undefined).
Return value
atoi returns the converted value of the input string. If the string cannot be converted to a number of the corresponding type (int), the return value is 0.
See also
Example
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
int n;
char *str = "12345";
n = atoi (str);
printf ("string = %s integer - %d\n", str, n);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdlib.h/atoi/
· short form /3.1/atoi/