Search code examples
cwchar-t

Comparing wchar_t with hex value


I have a problem when comparing wchar_t with hex value.

wchar_t c;
FILE *f = fopen("input1.txt", "r");
fwscanf(f, L"%lc", &c); // c is 'ệ'
printf("%d", c == L'\0x1ec7'); 

'ệ' is 0x1ec7 hex. But the result is 0. And how to compare wchar_t with hex value?


Solution

  • The correct notation is L'\x1ec7', not L'\0x1ec7':

    #include <stdio.h>
    
    int main() {
      wchar_t const c = L'ệ';
      printf("%d", c == L'\x1ec7'); // prints 1
    }