1

I want my code to output unicode characters.
This is my code:

printf("\u2660"); //Spade character

When compiling and executing with Cygwin, it works just fine and the spade character (♠) is displayed.
However, it doesn't work with MinGW, as the UTF-8 encoding is displayed as three characters (ÔÖá).

In the executable, the character is stored as UTF-8 in both cases, so the issue doesn't come from compiling.

So, why is the console behaving differently between Cygwin and MinGW?
Is there a fix to display UTF-8 with MinGW too?

Thorgaran
  • 38
  • 1
  • 6
  • 2
    Perhaps MinGW and Cygwin uses different terminal emulators/console window applications? – Some programmer dude Jun 01 '20 at 13:12
  • Here read this: https://stackoverflow.com/questions/771756/what-is-the-difference-between-cygwin-and-mingw – isrnick Jun 01 '20 at 13:17
  • @isrnick thank you. Why is Windows not trying to display UTF-8 though? It'd be much more convenient if I could release the executable without having to distribute cygwin.dll with it. – Thorgaran Jun 01 '20 at 13:34
  • @Thorgaran Command Prompt is ancient and there is no full compatibility with Unicode. There is the new Windows Terminal which should eventually replace it, and you could try to use it instead and look into making it into a requirement to run your software. – isrnick Jun 01 '20 at 13:48
  • 1
    https://devblogs.microsoft.com/commandline/windows-command-line-unicode-and-utf-8-output-text-buffer/ – matzeri Jun 01 '20 at 13:49
  • Or try this: [Having problems printing åäö (├Ñ ├à | ├ñ ├ä | ├ ├û)](https://stackoverflow.com/questions/60475759/having-problems-printing-%c3%a5%c3%a4%c3%b6-%c3%91-%c3%a0-%c3%b1-%c3%a4-%c3%82-%c3%bb) – the busybee Jun 01 '20 at 15:40
  • 2
    If you run the program and redirect output to a file `a.out > t.bin` under both systems, the byte dump the content of `t.bin`. If same, then you have a console difference - else it is a `a.out` difference. – chux - Reinstate Monica Jun 01 '20 at 15:55
  • You can use mintty with mingw https://superuser.com/questions/955424/how-can-i-use-mintty-as-the-terminal-emulator-for-mingw-msys – matzeri Jun 01 '20 at 17:56

1 Answers1

2

How are you running your MinGW application in a console? There are different ways:

  • Command Prompt
  • MinTTY (typically how MSYS2 shell is started)
  • some other tool like Conzole2 or ConsoleZ

Either way you should go to Properties or Options (for the first 2 by clicking on the icon on the top left of the console window) and change the font to a font that supports Unicode.

Also, in your application use wide character output like this: wprintf(L"\u2660");

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
  • With the command prompt. Your fix works, but only on my computer, so it's not what I'm looking for. It'll definitely be useful to other people though, so thank you for answering. Since there is no easy fix and it "just works" with Cygwin, I'll probably drop support for MinGW, as the deadline is in two weeks. – Thorgaran Jun 02 '20 at 12:59