I try to parse text and find some characters in it. I use the code below. It works with normal characters like abcdef
but it does not work with öçşğüı
There are no standards surrounding embedding non-ASCII characters directly in your source file.
Instead, the C11 standard specifies that you can use Unicode code points:
wchar_t text[] = L"\u00f6\u00e7\u015f\u0131\u011f";
// Print whole string
wprintf(L"%s\n", text);
// Test individual characters
for (size_t i = 0; text[i]; ++i)
{
if ( text[i] == u'\u00f6' )
// whatever...
}
If you are in Windows then you face an extra problem that the Windows console can't print Unicode characters by default. You need to do the following:
_setmode(1, _O_WTEXT);
, which will need #include
.To restore normal text afterwards you can _setmode(1, _O_TEXT);
.
Of course, if you are outputting to a file or to a Win32 API function then you don't need to do those steps.