strtoumax() — Convert character string to uintmax_t integer type
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C99
Single UNIX Specification, Version 3 C++ TR1 C99 |
both | z/OS® V1R7 |
Format
#define _ISOC99_SOURCE
#include <inttypes.h>
uintmax_t strtoumax(const char * __restrict__ nptr,
char ** __restrict__ endptr, int base);
Compile requirement: Function
strtoumax() requires long long to be available.
General description
The strtoumax() function converts the string nptr to an uintmax_t integer type. Valid input values for base are 0 and in the range 2-36. The strtoumax() function is equivalent to strtoul() and strtoull(). The only difference being that the return value is of type uintmax_t. See strtoull for more information.
Returned value
If successful, strtoumax() returns the converted uintmax_t value, represented in the string.
If
unsuccessful, strtoumax() returns 0 if no conversion could be performed.
If the correct value is outside the range of representable values,
strtoumax() returns UINTMAX_MAX
. If the value of
base is not supported, strtoumax() returns 0.
If unsuccessful strtoumax() sets errno to one of the following values:
- Error Code
- Description
- EINVAL
- The value of base is not supported.
- ERANGE
- The conversion caused an overflow.
Example
#define _ISOC99_SOURCE
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
uintmax_t j;
int base = 10;
char *nptr, *endptr;
nptr = "20690239864abc";
printf("string = %s\n", nptr);
j = strtoumax(nptr, &endptr, base);
printf("strtoumax = %ju (base %d)\n", j, base);
printf("Stopped scan at %s\n\n", endptr);
}
Output
string = 20690239864abc
strtoumax = 20690239864 (base 10)
Stopped scan at abc
Related information
- inttypes.h
- strtoimax()
- strtol()
- strtoul()
- strtoll()
- strtoull()
- wcstoimax()
- wcstoumax()