2017-04-14 81 views
0

我是大学新生,参加使用C代码的电气和计算机工程课程。现在我们正在对最终的项目(编码老处女的游戏),我试图在控制台获取打印这些字符:C代码中的特殊字符

██████╗ ██╗  ██████╗   ███╗ ███╗ █████╗ ██╗██████╗ ██╗      
██╔═══██╗██║  ██╔══██╗  ████╗ ████║██╔══██╗██║██╔══██╗██║      
██║ ██║██║  ██║ ██║  ██╔████╔██║███████║██║██║ ██║██║      
██║ ██║██║  ██║ ██║  ██║╚██╔╝██║██╔══██║██║██║ ██║╚═╝      
╚██████╔╝███████╗██████╔╝  ██║ ╚═╝ ██║██║ ██║██║██████╔╝██╗      
╚═════╝ ╚══════╝╚═════╝   ╚═╝  ╚═╝╚═╝ ╚═╝╚═╝╚═════╝ ╚═╝      

但随之而来的是:

??????? ???  ???????   ???? ???? ?????? ?????????? ??? 
????????????  ????????  ????? ??????????????????????????? 
??? ??????  ??? ???  ????????????????????????? ?????? 
??? ??????  ??? ???  ????????????????????????? ?????? 
?????????????????????????  ??? ??? ?????? ????????????????? 
??????? ???????????????   ???  ?????? ????????????? ??? 

我甚至尝试以不同的方式保存.c文件,并将文本文件中的字符作为数组读取并打印出来,但也会出现相同的问题。这些角色是不可能使用的吗? 我在Visual Studios 2015上工作。任何帮助将不胜感激,我还是有点新东西这个东西。

+1

你的控制台(控制台仿真器),什么是[代码页](https://en.wikipedia.org/wiki/Code_page)使用它?您应该知道哪个代码页处于活动状态(或者如何将其更改为所需的代码页,可能来自旧的DOS时间,用于[╔和╝]符号(https://en.wikipedia.org/wiki/Box-drawing_character),如[ 437代码页](https://en.wikipedia.org/wiki/Code_page_437);或尝试unicode?)并查找用于格式化的符号代码。 – osgx

+1

[Windows命令行中的Unicode字符可能重复 - 如何?](http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how) –

回答

0

您应该考虑使用宽字符。
请参阅C标准库wchar.h

例如:

#include <stdio.h> 
#include <wchar.h> 
#include <stdlib.h> 

int main(int argc, char** argv) { 
    wchar_t widechar = L'\x220E'; 

    wprintf(L"%lc\n", widechar); 

    return EXIT_SUCESS; 
} 

输出: