输出扩展ASCII码-如何输出小白块
2017-04-07 19:20
2361 查看
Output the Extended ASCII(E-ASCII) in C - How to print the little white block in CMD window
When write the EX1-13 in The C Programming Language, I need to print the littile white block in CMD window.. Since the white block is included by the E-ASCII, my task is to find how output the E-ASCII.The E-ASCII of white block is 219, therefore I shall ouput it with the following codes:
#include<stdio.h> void main() { printf("%c\n",219); }
However, the screen prints the "?". Obviously, there is something wrong.
By searching on the internet, I find two solutions:
1. Output double byte characters
#include<stdio.h> void main() { printf("%c%c\n", 0xa8, 0x80); }
//输出双字节字符来实现输出小方块。这种方法的原理不太清楚,需要进一步了解。此外,方块占据普通字符两倍的宽度,使画图布局变得困难。
With these codes, I get the desired result. But, I still don't know why it happens. I will take some time to find out the principle of printing double byte character.
Besides, the printed block will occupy double spaces as general character dose, which makes the layout difficult.
2. Output E-ASCII characters
The code page of the CMD window is 936(ANSI/OEM-GBK)by default to display Simplified Chinese. We have to change the code page to 437(OEM-American) to display all of the Extended ASCII.#include<stdio.h> #include<windows.h> // This header must be included. void main() { SetConsoleOutputCP(437); printf("%c\n",219); }
//更改代码页变量来实现直接输出扩展ASCII码,方便、易懂。方块与普通字符占据相同空间,便于布局。
Then the problem is perfectly fixed. The printed block occupy the same place as general character dose.
相关文章推荐
- 输出扩展ASCII码-如何输出小白块
- 声明两个变量:int n1=10,n2=20;要求将两个变量交换,最后输出n1为20,n2为10。扩展(*):不使用第三个变量如何交换?
- 如何把枚举元素的描述输出(不使用反映和扩展方法(3.5才支持呢)
- javascript输出AscII码扩展集中的字符方法
- javascript输出AscII码扩展集中的字符
- 如何定制Sink扩展.Net Remoting功能
- 如何使用Sybase ASE数据库的扩展存储过程?
- 如何执行,获取子进程的输出
- 如何设置Image保存时的文件扩展名
- 关于如何使用struts标签输出值为map的list
- 如何把rose模型产生的代码输出到指定的目录下?
- 关于如何写firefox扩展的英文入门文档。
- 如何建一个32位的数字用会编写个输出模块?
- PHP扩展中如何遍历数组?(ZEND API)
- 如何取得其它程序输出结果
- [导入]java中如何执行本地程序并捕获out和err输出
- 如何执行本地程序并捕获out和err输出(written in Java)
- 如何在PB中使用ASCII码为0的字符?(原创)
- ★ 如何将网页数据输出为Excel或Word文件
- java中如何执行本地程序并捕获out和err输出