Guardian C Library Calls Reference Manual

strtol
3-212 128833Guardian TNS C Library Calls Reference Manual
Reference to Library Calls
strtol
The strtol function converts a string of characters to a long int value using a specified
base.
str_ptr
points to the string to convert.
end_ptr_ptr
points to the variable of type pointer to char where strtol stores a pointer to the first
unrecognized character in *str_ptr.
base
specifies the base of the long integer. It can be in the range from 0 to 36. If base is
zero, strtol scans for a valid integer constant, optionally preceded by a sign but
without a suffix.
If base is less than 0, equal to 1, or greater than 36, strtol does not process the input
string. It returns zero and sets end_ptr_ptr to &str_ptr.
For bases greater than 10, strtol interprets the characters a through z (and A through
Z) as digits representing the values 10 through 35.
Return Value
is the converted long value if the conversion is successful. If strtol could perform no
conversion, it returns zero. If the correctly converted value would cause overflow,
strtol returns LONG_MAX or LONG_MIN, depending on the sign of the value, and
sets errno to ERANGE (a range error).
Usage Guidelines
The strtol function skips all leading space characters (as defined by isspace) in
*str_ptr.
The strtol function halts scanning when it encounters an unrecognized character.
#include <stdlibh>
long strtol(const char *str_ptr, char **end_ptr_ptr,
int base);