strtoimax Function

Convert string to greatest-width integer integer value.

Include

<inttypes.h>

Prototype

intmax_t strtoimax(const char * restrict nptr, char ** restrict endptr, int base);

Arguments

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 strtoimax function attempts to convert the first part of the string pointed to by nptr to an intmax_t integer value. If the value of base is unsupported, errno will be set to EINVAL.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{ 
  char * string = "-1234abcd";
  char * final;
  intmax_t result;
  
  result = strtoimax(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 -1234; final string part is "abcd"