Guardian C Library Calls Reference Manual

Reference to Library Calls
Guardian TNS C Library Calls Reference Manual128833 3-11
atoi
atoi
The atoi function converts a string to a value of type int.
str_ptr
points to the string to convert.
Return Value
is the numeric value of the string *str_ptr, expressed as an int value, atoi returns a
value of zero if the first nonspace character in *str_ptr is not a sign or a decimal
digit.
Usage Guidelines
The atoi function begins the conversion by skipping any leading space characters (as
defined by the isspace function) in *str_ptr. It then scans for a valid int constant,
continuing until it encounters an invalid character or the null character terminating
the string.
Example
This example converts the string “123” to an integer:
#include <stdlibh>
#include <stdioh>
int main(void)
{
int i;
char *string;
string = " 123";
i = atoi(string);
printf("%d\n",i); /* prints "123" */
}
#include <stdlibh>
int atoi(const char *str_ptr);