The iswxdigit() function is defined in <cwctype> header file.
iswxdigit() prototype
int iswxdigit(wint_t ch);
The iswxdigit() function checks if ch is a hexadecimal numeric character as classified by the current C locale. The available hexadecimal numeric characters are:
- Digits (0 to 9)
- Lowercase alphabets from a to f
- Uppercase alphabets from A to F
iswxdigit() Parameters
- ch: The wide character to check.
iswxdigit() Return value
- The iswxdigit() function returns non zero value if ch is a hexadecimal numeric character.
- It returns zero if ch is not a hexadecimal numeric character.
Example: How iswxdigit() function works?
#include <cwctype>
#include <iostream>
#include <cwchar>
#include <clocale>
using namespace std;
void ishexadecimal(wchar_t *str)
{
bool flag = false;
for (int i=0; i<wcslen(str); i++)
{
if (!iswxdigit(str[i]))
{
flag = true;
break;
}
}
if (flag)
wcout << str << L" is not a valid hexadecimal number" << endl;
else
wcout << str << L" is a valid hexadecimal number" << endl;
}
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t str[] = L"ă3ë1f";
ishexadecimal(str);
wchar_t str1[] = L"12abf";
ishexadecimal(str1);
return 0;
}
When you run the program, the output will be:
ă3ë1f is not a valid hexadecimal number 12abf is a valid hexadecimal number