strtoumax Function

Convert string to maximum-width unsigned integer value.

Include

<inttypes.h>

Prototype

uintmax_t strtoumax(const char * restrict nptr, char ** restrict endptr, int base);

Argument

nptr
the string to attempt to convert
endptr
pointer to the remainder of the string that was not converted
base
The base of the conversion

Return Value

The converted value, or 0 if the conversion could not be performed.

Remarks

The strtoumax function attempts to convert the first part of the string pointed to by nptr to an uintmax_t integer value.

Example

#include <inttypes.h>
#include <stdio.h>

int main(void)
{ 
  char * string = "-1234abcd";
  char * final;
  untmax_t result;
  
  result = strtoumax(string, &final, 10);
  printf("The integer conversion of the string \"%s\" is %" PRIdMAX "; final string part is \"%s\"\n", string, result, final);
}

Example Output

The integer conversion of the string "-1234abcd" is 18446744073709550382; final string part is "abcd"