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.

wcstoimax() function
#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 10
wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);
wchar_t wstr2[] = L"1000";
ret = wcstoimax(wstr2, &endptr, 2); // base 2
wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);
wchar_t wstr3[] = L" FFProgramming languages are awesome!!!"; //spaces in the start will be ignored
ret = wcstoimax(wstr3, &endptr, 16); // base 16
wprintf(L"endptr: %ls \nConverted Value: %ld\n\n", endptr, ret);
return 0;
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved