Reputation: 29
So i started off by placing an array of char char symbols[52] = { '\x03' , '\x04', etc. . etc.) and the first time I did it, it actually did print the hearts,spades, etc. but after changing my system locale to a korean one (idk if this is what caused it), it started giving me weird symbols that had nothing to do with it. I also tried to do it in another computer and it actually compiled the symbols correctly. However, then I tried moving it on to linux and it printed weird squares with a 0 0 0 3 in it.
Does anyone know why these appear or is there a better way to print these symbols?
P.S.: I'm using Visual Studio in Windows and then used the .c code in Linux
Upvotes: 1
Views: 13935
Reputation: 91189
Linux systems typically use UTF-8 encoding, in which:
Edit: Unfortunately, the Windows command prompt doesn't support UTF-8, but uses the old DOS code pages. If you want your program to work cross-platform, you'll have to do something like:
#if defined(_WIN32) || defined(__MSDOS__)
#define SPADE "\x06"
#define CLUB "\x05"
#define HEART "\x03"
#define DIAMOND "\x04"
#else
#define SPADE "\xE2\x99\xA0"
#define CLUB "\xE2\x99\xA3"
#define HEART "\xE2\x99\xA5"
#define DIAMOND "\xE2\x99\xA6"
#endif
Upvotes: 5
Reputation: 120031
On Linux:
<somelanguage>_<SOMEPLACE>.UTF-8
(type locale
in the termunal).setlocale(LC_ALL, "")
at the beginning of your program, as the language standard requires, and use char
, not wchar_t
.On Windows:
chcp 65001
in the console. No, really!Upvotes: 0
Reputation: 13196
If your Linux terminal character set is set to UTF-8, as it usually is, then you should be able to display all of the Unicode glyphs you have fonts for. Suit symbols are in the neighborhood of \u2660.
printf("A\u2660");
Should print "A" and the spade symbol, for example.
Upvotes: 0
Reputation: 263497
Characters like '\x03
are control characters. \x03
in particular is the character you get when you type Control-C (though typing that character often has other effects).
Some fonts happen to assign images to control character. As far as I know, there's no standard for doing so. Apparently in your previous configuration, some of the control character happened to be displayed as playing card suit symbols.
There are standard Unicode characters for those symbols:
2660 BLACK SPADE SUIT
2661 WHITE HEART SUIT
2662 WHITE DIAMOND SUIT
2663 BLACK CLUB SUIT
2664 WHITE SPADE SUIT
2665 BLACK HEART SUIT
2666 BLACK DIAMOND SUIT
2667 WHITE CLUB SUIT
(The numbers are in hexadecimal.)
Different systems encode Unicode in different ways. Windows usually uses some form of UTF-16. Linux usually uses UTF-8, but you can vary that by setting the locale.
Upvotes: 1