怎样用c语言程序提取汉字库中的数据?急求!

怎样用c语言程序提取汉字库中的数据?急求!,第1张

FILE *PHZK16

/*

*HZK16字库初始化_打开字库

*/

void _InitHzk16()

{

PHZK16=fopen("Hzk16","世信闹rb")

if(!PHZK16){

printf("error in Hzk16,not exist\n")

system("pause")

exit(1)

}

}

/*

*取得字码

*/

void _GetHzk16Code(unsigned char code[],unsigned char bytes[])

{

unsigned char qh,wh

unsigned long offset

qh=code[0]-0xa0/*得到区号*/

wh=code[1]-0xa0/*得到位号*/

offset=(94*(qh-1)+(wh-1))*32L/*得到偏移位置*/

fseek(PHZK16,offset,SEEK_SET)/*移文件指针到要读取的汉字字模处*/

fread(bytes,32,1,PHZK16)/*读取32 个汉字的汉坦禅字字模*/

}

/******************************************************************************************************************/

/*下面这个代码 是C画图模式下可用*/

/*

*改变x、y(左上点)的位置,就可以搜罩实现文字的横向输出

*单个文字输出

*/

void _InputHzk16(int x,int y,unsigned char code[],int color)

{

int i,j,x0=0,y0=0

unsigned char s,mat[32]

_GetHzk16Code(code,mat)

for(i=0i<16i++){

s=mat[2*i]

x0=x+7

y0=y+i

while(s){

if(s%2){

putpixel(x0,y0,color)

}

s=s/2

x0--

}

s=mat[2*i+1]

x0=x+15

while(s){

if(s%2){

putpixel(x0,y0,color)

}

s=s/2

x0--

}

}

}

# include <stdio.h>

# include <stdlib.h>

# include <io.h>

# include <凯让conio.h>

# include <dos.h>

# include <fcntl.h>

# define NUM 20

struct

{

unsigned int code

unsigned char dot [32]

}lib[NUM]

union

{

unsigned char ch[2]

unsigned int i

}ch_code

FILE *fphz,*fpin,*fpout

void drawdots (unsigned int incode,int num)

int main (int argc,char *argv[])

{

int num

int i,j

if (argc <3)

{

printf("Format must be:makepoint <fileinput><fileoutput>\n")

exit(1)

}

fphz=fopen ("hzk16","rb")

if (fphz==NULL)

{

printf ("Can't open the chinaese library hzkl16.\n")

exit(1)

}

fpin =fopen (argv[1] ,"rb")

if (fpin==NULL)

{

printf (" Can't open the source file:%s\n",argv[1])

exit (1)

}

fpout =fopen (argv[2] ,"wt" )

if(fpout==NULL)

{

printf ("Can't open or creat destination file:%s\n",argv[2])

fclose (fphz) fclose (fpin) exit(1)

}

num=0

while (!feof (fpin) )

{

fread (&ch_code.ch[1],1,1,fpin)

fread (&ch_code.ch[0],1,1,fpin)

lib[num].code=ch_code.i

drawdots(ch_code.i,num)

fprintf (fpout,"\返孙烂t0x%4x,\n",lib[num].code)

for (i=0i<漏漏8i++)

{

fprintf (fpout,"\t")

for (j=0j<2j++)

fprintf (fpout,"%02xH",lib[num].dot [i*2+j])

fprintf (fpout,"\n")

}

num++

fclose(fphz) fclose(fpin)fclose (fpout)

return (0)

}

return 0

}

void drawdots(unsigned int incode,int num)

{

unsigned int q_numb ,w_numblong chpos

ch_code.i =incode

q_numb=(ch_code.ch[1]-0xa1)&0x07f

w_numb=(ch_code.ch[0]-0xa1)&0x07f

chpos=(q_numb*94+w_numb)*32

fseek(fphz,chpos,SEEK_SET)

fread (lib[num].dot,sizeof (char),32,fphz)

}

建立颤迹一个足够大的字符型数组;

以文本方式读打开原文件

按字符方式读取文件,每读一个字符判断一下是否为汉字编码(<0),若是则存桐码入字符数组,不是则跳过读取下一个字符,直到文件结束。

设原文件在当前目录下,名为123.txt,举例代码如下:

//#include "stdafx.h"//If the vc++6.0, with this line.

#include "stdio.h"

#include "stdlib.h"

int main(void){

    char s[1000],ch

    FILE *fp

    int i=0

    if((fp=fopen("123.txt","r"))==NULL){

        printf("Open the file failure...\n")

        exit(0)

    }

   局洞哪 while((ch=fgetc(fp))!=EOF)

        if(ch<0)

            s[i++]=ch

    fclose(fp)

    s[i]='\0'

    printf("%s\n",s)//打出来看看

    return 0

}

注:原文件内容是“fjkslauti我rophk134是2315学jkal 习C语言jks新dajus手jfkdsla”

输出是“我是学习语言新手”


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12554767.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存