C实现打印汉字点阵

#include 
#include 

#define N  32

int main(int argc, const char *argv[])
{
	int i,j;
	char ch[N * 4] = 
	{
		/* 以下是 '我' 的 16点阵宋体 字模,32 byte */
		0x06,0x40,0x38,0x50,0x08,0x48,0x08,0x48,
		0x08,0x40,0xFF,0xFE,0x08,0x40,0x08,0x48,
		0x0E,0x28,0x38,0x30,0xC8,0x20,0x08,0x50,
		0x09,0x92,0x08,0x0A,0x28,0x06,0x10,0x02,

		/* 以下是 '爱' 的 16点阵宋体 字模,32 byte */
		0x00,0xF8,0x3F,0x90,0x12,0x10,0x09,0x20,
		0x3F,0xFE,0x22,0x02,0x42,0x00,0x3F,0xFC,
		0x04,0x00,0x07,0xF0,0x0C,0x20,0x0B,0x40,
		0x10,0xC0,0x63,0x30,0x8C,0x0E,0x30,0x04,

		/* 以下是 '中' 的 16点阵宋体 字模,32 byte */
		0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,
		0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
		0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,
		0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,

		/* 以下是 '国' 的 16点阵宋体 字模,32 byte */
		0x00,0x00,0x7F,0xFC,0x40,0x04,0x5F,0xF4,
		0x41,0x04,0x41,0x04,0x41,0x04,0x4F,0xE4,
		0x41,0x44,0x41,0x24,0x41,0x24,0x5F,0xF4,
		0x40,0x04,0x40,0x04,0x7F,0xFC,0x40,0x04,
	};

#if 1
	for(i = 0; i < sizeof(ch); i++)
	{
		for(j = 0; j < 8; j ++)
		{
			if(ch[i] & 0x80 >> j)
				putchar('@');
			else
				putchar('.');
		}
		if( i % 2 )
			putchar(10);
		if(!((i + 1) %  32))
			putchar(10);
	}

#else

	for(i = 0; i < sizeof(ch); i += 2)
	{
		for(j = 0; j < 8; j ++)
		{
			if(ch[i] & 0x80 >> j)
				putchar('#');
			else
				putchar('.');
		}
		for(j = 0; j < 8; j ++)
		{
			if(ch[i + 1] & 0x80 >> j)
				putchar('#');
			else
				putchar('.');
		}
		putchar(10);
		if(i %  32)
			putchar(10);
	}

#endif

	return 0;
}

测试结果

C实现打印汉字点阵_第1张图片

你可能感兴趣的:(C,Demo)