Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

strtoimax(3) OSS Library Calls Reference Manual
Character 0123456789ABCDEFGHIJ
abcdefghij
Value 012345678910111213141516171819
The subject string can optionally be preceded by a + (plus sign) or - (minus sign), but cannot
include an integer sufx (such as L). If the subject string is preceded by a - (minus sign), the con-
verted integer value has a negative value. If the value of base is 16, the characters 0x or 0X may
optionally precede the sequence of letters or digits, following the sign, if present.
The character string is parsed to skip the initial space characters (as determined by the isspace( )
function). Any nonspace character is the starting of a potential subject string that may form an
integer in the base specified by the base parameter. The subject sequence is defined to be the
longest initial substring that is of the expected form of long integer. Any character that does not
satisfy this expected form begins the final sequence of unrecognized characters. The
strtoimax( ) function sets the location pointed to by the endptr parameter to point to this final
sequence of unrecognized characters except when endptr is a null pointer.
The LC_CTYPE category of the locale controls what characters are treated as spaces but does
not effect the interpretation of characters as part of the subject string. The characters in the sub-
ject string are always treated as if the locale was the C/POSIX locale.
In the TNS/E native environment, all locales are supported.
EXAMPLES
The following example converts a character string to a intmax_t value.
#include <stdio.h>
#include <inttypes.h>
#include <locale.h>
#include <errno.h>
#define LENGTH 40
main()
{
char String[LENGTH], *endptr;
intmax_t retval;
(void)setlocale(LC_ALL, "");
if (fgets(String, LENGTH, stdin) != NULL) {
errno = 0;
retval = strtoimax ( String, &endptr, 0 );
if (retval == 0 && (errno != 0
|| String == endptr)) {
/* No conversion could be performed */
printf("No conversion performed\n");
} else if (errno !=0 && (retval == LONG_MAX
|| retval == LONG_MIN)) {
/* Error handling */
} else {
/* retval contains intmax_t */
printf("Integer in decimal is %d\n", retval);
}
}
}
6178 Hewlett-Packard Company 527187-017