strtoimax, strtoumax
Header: <inttypes.h>
Interprets an integer value in a byte string pointed to by nptr.
# Declarations
intmax_t strtoimax( const char* restrict nptr,
char** restrict endptr, int base );
(since C99)
uintmax_t strtoumax( const char* restrict nptr,
char** restrict endptr, int base );
(since C99)
# Parameters
nptr: pointer to the null-terminated byte string to be interpretedendptr: pointer to a pointer to characterbase: base of the interpreted integer value
# Example
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char* endptr = NULL;
printf("%ld\n", strtoimax(" -123junk", &endptr, 10)); // base 10
printf("%ld\n", strtoimax("11111111", &endptr, 2)); // base 2
printf("%ld\n", strtoimax("XyZ", &endptr, 36)); // base 36
printf("%ld\n", strtoimax("010", &endptr, 0)); // octal auto-detection
printf("%ld\n", strtoimax("10", &endptr, 0)); // decimal auto-detection
printf("%ld\n", strtoimax("0x10", &endptr, 0)); // hexadecimal auto-detection
// range error: LONG_MAX+1 --> LONG_MAX
errno = 0;
printf("%ld\n", strtoimax("9223372036854775808", &endptr, 10));
printf("%s\n", strerror(errno));
}