如何在C和Linux中打印黑桃,心形,菱形等? [英] How to print spades, hearts, diamonds, etc. in C and Linux?
问题描述
所以我从放置一个char数组开始字符符号[52] = {'\ x03','\ x04'等.等等.)我第一次这样做时,它确实打印出了心形,黑桃色等,但是在将系统区域设置更改为韩语(如果是IDK的话,则是idk)之后,它开始给我提供了无用的奇怪符号用它.我还尝试在另一台计算机上执行此操作,它实际上正确地编译了符号.但是,然后我尝试将其移到linux上,并在其中打印出带有0 0 0 3的怪异方块.
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 .:我在Windows中使用Visual Studio,然后在Linux中使用.c代码
P.S.: I'm using Visual Studio in Windows and then used the .c code in Linux
推荐答案
Linux系统通常使用UTF-8编码,其中:
Linux systems typically use UTF-8 encoding, in which:
- ♠= U + 2660 ="\ xE2 \ x99 \ xA0"
- ♣= U + 2663 ="\ xE2 \ x99 \ xA3"
- ♥= U + 2665 ="\ xE2 \ x99 \ xA5"
- ♦= U + 2666 ="\ xE2 \ x99 \ xA6"
不幸的是, Windows 命令提示符不支持UTF-8,但是使用了旧的DOS代码页.如果要让程序跨平台运行,则必须执行以下操作:
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
这篇关于如何在C和Linux中打印黑桃,心形,菱形等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!