How to store multi-byte into a char array in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main() 
{
    setlocale(LC_ALL, "C.UTF-8");

    printf("%lc\n", 0x00004e2d);
    printf("%lc\n", 0x00006588);
    printf("%lc\n", 0x00004a3d);

    wchar_t *arr = malloc(3 * sizeof(wchar_t));
    
    arr[0] = 0x00004e2d;
    arr[1] = 0x00006587;
    arr[2] = 0x00004a3d;
    
    printf("%ls\n", arr);
    
    free(arr);
}



/*
run:

中
斈
䨽
中文䨽

*/

 



answered Apr 22, 2024 by avibootz
edited Apr 22, 2024 by avibootz

Related questions

1 answer 112 views
112 views asked Apr 12, 2024 by avibootz
1 answer 145 views
1 answer 180 views
2 answers 234 views
234 views asked Aug 10, 2015 by avibootz
...