The wcstoimax()
function converts the contents of a wide-character string to the integral equivalent of the specified base.
The wcstoimax()
function is defined in the following library:
#include<inttypes.h>
The following is the declaration of wcstoimax()
function:
intmax_t wcstoimax(const wchar* wstr, wchar** endptr, int base);
wstr
: The pointer to the null-terminated wide-character string containing the integral number.endptr
: This holds the address of the next character after the last valid numeric character in wstr.base
: This specifies the base for the number being converted.Upon successful conversion, the function returns the integral value in the base specified. On the other hand, the function returns 0
if no conversion can be performed.
The code below illustrates the use of wcstoimax()
function in C.
#include <inttypes.h>#include <wchar.h>int main(void){wchar_t* endptr;wchar_t wstr[] = L"1234qwerty";intmax_t ret = wcstoimax(wstr, &endptr, 10); // base 10wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);wchar_t wstr2[] = L"1000";ret = wcstoimax(wstr2, &endptr, 2); // base 2wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);wchar_t wstr3[] = L" FFProgramming languages are awesome!!!"; //spaces in the start will be ignoredret = wcstoimax(wstr3, &endptr, 16); // base 16wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);return 0;}
Free Resources