说明:
我们常用的字库文件有 HZK16[此程序所需文件],HZK12,ASC16 文件等等。不过这些文件都是前辈已经做好了的,其中包含常用的所有汉字。以下示例程序就是通过 HZK16 字库文件来生成我们自己的字库文件,不过生成的这个字库文件只包含我们所需要的汉字信息,而把多余的汉字丢掉,从而达到减小软件大小的目的!
程序中“Input the name of the text file:”提示我们输入已经准备好的待转换为字库文件的文本文件路径及文件名,该文本文件内应包含程序中我们所要使用的汉字信息!点击下载 myhzk.txt
程序中“Input the name of new ziku file:”提示我们输入经程序转换后的字库文件的文件路径及文件名,这个文件即是我们所要获取的字库文件!点击下载 MYHZK16[由上面提供的 myhzk.txt 制作的汉字库文件]
程序源码:
/* 本程序生成自制小字库文件 */
#include<stdio.h>
main(){
int i=0;
FILE *fp,*fw,*fr;
char buffer[32];
char txt[64],myhzk[64]; /* 待输入的文本文件名,及自制字库文件名 */
char qhs,whs;
unsigned char qh,wh;
unsigned long location;
printf("Input the name of the text file:\n");
scanf("%s",txt);
while((fr=fopen(txt,"r"))==NULL){
printf("File \"%s\" do not exist!\n\nInput again:\n",txt);
scanf("%s",txt);
}
printf("\nInput the name of new ziku file:\n");
scanf("%s",myhzk);
if((fw=fopen(myhzk,"wb+"))==NULL){
printf("Can't create %s!",myhzk);
return(0);
}
if((fp=fopen("hzk16","rb"))==NULL){
printf("Can't open hzk16!");
return(0);
}
qhs=fgetc(fr);
whs=fgetc(fr);
while(!feof(fr)){
qh=qhs-0xa0;
wh=whs-0xa0;
location=(94*(qh-1)+(wh-1))*32L;
fseek(fp,location,SEEK_SET);
fread(buffer,32,1,fp);
fwrite(buffer,32,1,fw);
qhs=fgetc(fr);
whs=fgetc(fr);
i++;
}
printf("\n%d words succeed!",i); /* 显示总转换字数 */
getch();
fclose(fp);
fclose(fr);
fclose(fw);
}