|
/*單個漢字庫字摸提取程序,tc2.0編譯*/ #include "stdio.h" #include "dos.h" #include "process.h" #include "string.h" void main(void) { long int num_bytes,qm,wm; unsigned char d,i,j,k,a[132],b[132]; unsigned char * data; unsigned char * hz; static unsigned char dd[103]; FILE *fp; // if ((fp=fopen("hzk16f","rb"))==NULL) { printf("can't open hzk16\n"); exit(1); } clrscr(); while (1) {
data=(unsigned char *) malloc(33); printf("please input:\n"); scanf("%s",dd); /*輸入一個漢字*/ qm=* dd; /*通過區(qū)位碼計算其在hzk16f文件中的偏移地址*/ qm=qm-161; if (qm>87) exit(0); wm=* (dd+1); wm=wm-161; if (wm>94) exit(0); num_bytes=((long)qm*94+wm)*32; fseek(fp,num_bytes,SEEK_SET); fgets(data,33,fp); for (i=0;i<32;i++) b[i]=* data++; for (i=0;i<32;i+=2) a[i/2]=b[i]; for (i=0;i<32;i+=2) a[i/2+16]=b[i+1]; for (i=8;i<16;i++) b[i]=a[i]; for (i=8;i<16;i++) a[i]=a[i+8]; for (i=8;i<16;i++) a[i+8]=b[i]; /*轉(zhuǎn)換,hzf16f在電腦的儲存格式是以行為字節(jié)計算的,一般的lcd都采用以列為字節(jié)計算*/ for (k=0;k<32;k+=8) { for (j=0;j<8;j++) { d=0; for (i=0;i<8;i++) { if (a[i+k]>=0x80) { switch (i) { case 0:d+=1;break; case 1:d+=2;break; case 2:d+=4;break; case 3:d+=8;break; case 4:d+=0x10;break; case 5:d+=0x20;break; case 6:d+=0x40;break; case 7:d+=0x80;break; } } } for (i=0;i<8;i++) a[i+k]<<=1; b[j+k]=d; } } clrscr(); printf("/*%s:*/\n",dd); /*輸出0x00格式的16進制數(shù)*/ for (k=0;k<32;k+=8) { for (j=0;j<8;j++) printf("0x%x,",b[j+k]); printf("\n"); } getch(); } } |