How to use special characters in C?

I realized that my program should be able to handle special characters, such as Japanese or Chinese. But I know that the built-in char type is far from enough. So how can I use these special characters in a C program?

+4
source share
4 answers

You need to use wide characters .

This is what you need for Unicode, they can get work with almost all the characters you drop, and this can do it, because - and this is the catch: it consumes more bytes (twice as much; it sounds tony, but for the most part, this is really not the case).

Note: In Windows programming, you use the TEXT("") macro to choose whether your characters are Unicode or ANSI. he will choose according to the settings of your project.
If you insist that it be Unicode, you can write a string prefixed with the letter L as follows: L"Unicode String"

The header file for working with wide characters is wchar.h .

+2
source

like this on windows vs :)

 #include <tchar.h> typedef struct _我的结构{ int 数据; TCHAR 字符串指针[100]; }我的结构; int main(int argc,char** argv){我的结构 我的变量 = {1, _T("字符串123abc")}; _tprintf(_T("%s, %d"),我的变量.字符串指针,我的变量.字符串指针); return 0; } 
+5
source

You can use UTF-8 encoding if you could live with that one byte! = One Unicode character.

+4
source

for languages ​​like Unicode, you can use wchar_t instead of char

+2
source

Source: https://habr.com/ru/post/1415491/


All Articles