What is wcstoimax() in C?
The wcstoimax() function converts the contents of a wide-character string to the integral equivalent of the specified base.
Library
The wcstoimax() function is defined in the following library:
#include<inttypes.h>
Declaration
The following is the declaration of wcstoimax() function:
intmax_t wcstoimax(const wchar* wstr, wchar** endptr, int base);
Parameters
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.
Return value
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.
Code
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
Copyright ©2026 Educative, Inc. All rights reserved