Print UTF-8 multibyte character in C

前端 未结 1 1472
孤街浪徒
孤街浪徒 2021-01-27 11:57

I wrote this code to print a UTF-8 multibyte string. But it does not print properly. Note: I am doing it in a Linux system.

#include 
#include <         


        
1条回答
  •  生来不讨喜
    2021-01-27 12:19

    Use \u instead of \x:

    #include 
    #include 
    
    int main()
    {
        char *locale = setlocale(LC_ALL, "");
        printf("\n locale =%s\n", locale);
        printf("test\n \u263a\u263b Hello from C\n");
    
        return 0;
    }
    

    This runs and produces the following output:

    $ gcc foo.c
    $ ./a.out 
    
     locale =C
    test
     ☺☻ Hello from C
    

    0 讨论(0)
提交回复
热议问题