⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3_24.c

📁 浙大《C语言设计基础课程设计》中的例程 有些比较好的代码!
💻 C
字号:
/*-------例程3-24-------*/
#include <stdio.h>
#include <graphics.h>

FILE *hzk_p;
void open_hzk(void);
void get_hz(char incode[],char bytes[]);
void dishz(int x,int y,char cade[],int color);
main()
{
	int x=20;
        int y=100;
	char *s="岱宗夫如何,齐鲁青未了。造化钟神秀,阴阳割昏晓。荡胸生层云,决眦入归鸟,会当凌绝顶,一览众山小。";
	int driver=DETECT;
	int mode=0;
        initgraph(&driver,&mode,"");
	open_hzk();
	while (*s!=NULL)
	{
		while (x<640 && (*s!=NULL))
		{
			dishz(x,y,s,LIGHTRED);
			x+=20;
			s+=2;
		}
		x=20;y+=20;
	}
	getch();
	fclose(hzk_p);
	closegraph();
}

void open_hzk()
{

	hzk_p=fopen("d:/zy/tc/hzk16","rb");
	if (!hzk_p){
		printf("The file HZK16 not exist! Enter to system\n");
	    getch();
		closegraph();
		exit(1);
	}
}

void get_hz(char incode[],char bytes[])
{
	unsigned char qh,wh;
	unsigned long offset;
	qh=incode[0]-0xa0;				/*得到区号*/
	wh=incode[1]-0xa0;			/*得到位号*/
	offset=(94*(qh-1)+(wh-1))*32L;	/*得到偏移位置*/
	fseek(hzk_p,offset,SEEK_SET);	/*移文件指针到要读取的汉字点阵处*/
	fread(bytes,32,1,hzk_p);			/*读取32字节的汉字点阵信息*/
}

void dishz(int x0,int y0,char code[],int color)
{
	unsigned char mask[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
        /*屏蔽点阵每行各位的数组*/
	int i,j,x,y,pos;
	char mat[32];
	get_hz(code,mat);
	y=y0;
	for (i=0;i<16;++i)
	{
		x=x0;
		pos=2*i;
		for(j=0;j<16;++j)
		{
                 /*屏蔽出汉字点阵的一个位,即一个点是1则显示,否则不显示该点*/
			if ((mask[j%8]&mat[pos+j/8])!=NULL)	
				putpixel(x,y,color);		    
			++x;
		}
		++y;
	}
}
/*-------例程3-24结束-------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -