Hi All,

I have been trying to get my head around this for DAYS now...

I'm using Windows 10 and Codeblocks IDE with MinGW compiler.

I'm told MinGW has some peculiarities to do with UTF8, Unicode and MultiByte characters?

I start by converting a char32_t Thai Character to Multibyte using c32rtomb(). That goes fine. It doesn't output to the console correctly but if I copy + paste it into notepad it displays absolutely fine.

HOWEVER, when I then try to convert that multibyte character to wchar_t I get anomalous strings, or (null) strings, or access violations or whatever, depending on how I attempt to output it using printf()...

Here is the code:

Code:
                    char32_t tester = U'ฐ'; //a Thai letter

                    int returned = NULL;
                    std::mbstate_t state {};
                    char output[MB_LEN_MAX] {};

                    returned = c32rtomb(output, tester, &state);

                    printf("[c32rtomb()]: Character Returned is: %s \n\n", output); //Displays incorrectly in console 
                                                      //but copies to clipboard fine...


                    wchar_t receiver;

                    mbtowc(NULL, NULL, 0); //Reset the function
                    
                    auto resultant = mbtowc(&receiver, output, MB_LEN_MAX);

                    printf("[mbtowc()]: Byte-length of returned character is: %u \n", resultant);
              
                    printf("[mbtowc()]: Data returned is: %d \n", receiver);
                    
                    wprintf(L"[mbtowc()]: Character Returned is: %c \n", receiver);
-The value of resultant is always 1 byte. Shouldn't the wchar_t character be larger than 1 byte?

- Am I using the wrong symbol (%c) in wprintf() to output the character?

-Anything else you can see going wrong?

I have asked this in other places but I don't think most people run the code themselves because the answers I received don't work.

I would particularly appreciate it if people tried this in Codeblocks IDE with MinGW compiler, since I've heard it's fiddly there but it's the only IDE I have access to right now.

Many thanks for your assistance and appreciation for your time!