📄 encoding.cpp
字号:
#include"head.h"
void Encoding()
{//利用已建好的哈夫曼树,对文件ToBeTran中的正文进行编码,然后将结果存入文件CodeFile中。
char c;
int i=1;
Node *p,*p1,*p2,*p3;
FILE *hfmTree,*CodeFile,*ToBeTran;
hfmTree=fopen("hfmTree","r+");
ToBeTran=fopen("ToBeTran.txt","r");
p=(Node *)malloc(sizeof(Node));
p->next=NULL;
p1=p;
while(!feof(hfmTree))
{//将哈夫曼树读入
p2=(Node*)malloc(sizeof(Node));
if(fread(p2,sizeof(Node),1,hfmTree)==1)
{
p1->next=p2;
p1=p2;
}
else break;
}
p1->next=NULL;
fclose(hfmTree);
CodeFile=fopen("CodeFile","wb+");
while(!feof(ToBeTran))
{
c=fgetc(ToBeTran);
p3=p->next;
while(p3!=NULL)
{
if(c==p3->a)
{//找到待编字符,并且找到其相应的编码,将其编码结果存入到CodeFile文件
fprintf(CodeFile,"%s",p3->c);break;
}
p3=p3->next;
}
}
fclose(CodeFile);
fclose(ToBeTran);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -