How to convert a multibyte char string to a multibyte wchar_t string in C

1 Answer

0 votes
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
#include <wchar.h>
 
int main(void)
{
    setlocale(LC_ALL, "en_US.utf8");
    
    const char* mbstr = u8"z\u00A7\u03B2\U0001F34C"; // or u8"z§β????"
    
    wchar_t wstr[5];
    mbstowcs(wstr, mbstr, 5);
    
    wprintf(L"char string: %s\n", mbstr);
    wprintf(L"wchar_t string: %ls\n", wstr);
}



/*
run:

char string: z§β????
wchar_t string: z§β????

*/


answered Apr 22, 2024 by avibootz

Related questions

1 answer 92 views
1 answer 122 views
1 answer 150 views
150 views asked Feb 11, 2023 by avibootz
...