atoi
Converts a string to an integer
#include <stdlib.h> intatoi
( const char *s
); longatol
( const char *s
); long longatoll
( const char *s
); (C99)
The atoi()
function converts a string of characters representing a numeral into a number of int
. Similarly, atol()
returns a long
integer, and in C99, the atoll()
function converts a string into an integer of type long long
.
The conversion ignores any leading whitespace characters (spaces, tabs, newlines). A leading plus sign is permissible; a minus sign makes the return value negative. Any character that cannot be interpreted as part of an integer, such as a decimal point or exponent sign, has the effect of terminating the numeral input, so that atoi()
converts only the partial string to the left of that character. If under these conditions the string still does not appear to represent a numeral, then atoi()
returns 0.