Guardian C Library Calls Reference Manual
atol
3-12 128833—Guardian TNS C Library Calls Reference Manual
Reference to Library Calls
atol
The atol function converts a string to a value of type long.
str_ptr
points to the string to convert.
Return Value
is the numeric value of the string *str_ptr, expressed as a long value, atol returns a
value of zero if the first nonspace character in *str_ptr is not a sign or a decimal
digit.
Usage Guidelines
•
The atol 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 long constant,
continuing until it encounters an invalid character or the null character terminating
the string.
Example
This example converts the string “1234567” to a long integer:
#include <stdlibh>
#include <stdioh>
int main(void)
{
long i;
char *string;
string = "1234567";
i = atol(string);
printf("%ld\n",i); /* prints "1234567" */
}
#include <stdlibh>
long atol( const char *str_ptr);