wcstoimax() — Convert a wide-character string to a intmax_t

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>

intmax_t wcstoimax(const wchar_t * __restrict__ nptr, 
                   wchar_t ** __restrict__ endptr, int base);
Compile requirement: Function wcstoimax() requires long long to be available.

General description

The wcstoimax() function converts the wide-character string nptr to an intmax_t integer type. Valid input values for base are 0 and in the range 2-36. The wcstoimax() function is equivalent to wcstol() and wcstoll(). The only difference being that the return value is of type intmax_t. See wcstoll() for more information.

Returned value

If successful, wcstoimax() returns the converted value, if any.

If unsuccessful, wcstoimax() returns 0 if no conversion could be performed. If the correct value is outside the range of representable values, wcstoimax() returns INTMAX_MAX or INTMAX_MIN, according to the sign of the value. If the value of base is not supported, wcstoimax() returns 0.

If unsuccessful wcstoimax() 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 <stdio.h>        

 int main(void)                                       
{                                                    
   wchar_t *nptr;                                    
   wchar_t *endptr;                                  
   intmax_t  j;                                      
   int base = 10;                                    
   nptr = L"10110134932";                            
   printf("nptr = `%ls`\n", nptr);                   
      j = wcstoimax(nptr, &endptr, base);            
      printf("wcstoimax = %jd\n", j);            
      printf("Stopped scan at `%ls`\n\n", endptr);
}                                                    



Output 

nptr = `10110134932`      
wcstoimax = 10110134932
Stopped scan at ``     

Related information