/*文件中有些参数定义的比较大,主要是为了适应较大文件的压缩*/
#include
#include
#include
#include//用以删除多余的中间文件
#define M 100000000000//最大字符数
int op,co[100];//编码表的扫描指针,简易栈co[]
typedef struct Hfnode //哈弗曼树结点类型
{
int data;//权值域
char zimu;//存储字母
struct Hfnode *Lson,*Rson,*next;//儿子链域和森林链域
}Hfnode,*Hfptr;
typedef struct snode//静态数组结点类型
{
char c;//字符
int f1;//频度
}snode;
typedef struct Lnode//编码表结点类型
{
char c;
struct Lnode *next;
}Lnode,*Lptr;
void gotoxy(int x,int y){
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
void paint1()
{
int i,j;
for(j=0;j<4;j++)
{for(i=0;i<70;i++)//简易画线代码,呵呵
putchar(95);
putchar(10);putchar(10);putchar(10);
}
gotoxy(0,4);
printf("请输入需打开的文件路径:");
gotoxy(0,7);
printf("请输入压缩文件的保存路径:");
gotoxy(0,10);
printf("此次文件压缩率为:");
gotoxy(0,13);
}
void paint2()
{
int i,j;
for(j=0;j<4;j++)//画4行直线
{for(i=0;i<70;i++)//简易画线代码,呵呵
putchar(95);
putchar(10);putchar(10);putchar(10);
}
gotoxy(0,4);
printf("请输入解压文件的路径:");
gotoxy(0,7);
printf("请输入还原文件的保存路径:");
gotoxy(0,10);
printf("还原结果:");
}
int putdata(Lptr strhead)//输入函数
{
Lptr p;
FILE*fp;
int i=0;
char infile[30];
p=strhead;
gotoxy(0,5);
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("文件打开错误!\n");
exit(0);
}
while(!feof(fp))
{
p->c=fgetc(fp)&0xFF;
p->next=new Lnode;
p=p->next;
/*putchar(ch[i]);*/
i++;
}
putchar(10);
fclose(fp);
return(i-1);
}
int stat(Lptr p,snode ch2[],int num)//统计函数
{
int i,j,last=0;
for(i=0;i
{
for(j=0;ch2[j].c!=p->c&&j!=last;)
j++;
if(j==last)
{
ch2[j].c=p->c;
ch2[j].f1=1;
last++;
}
else ch2[j].f1++;
p=p->next;
}
return(last);
}
void order(snode ch2[],int n)//冒泡排序
{
int i,j,k,t;
char a;
for(i=0;i
{
k=i;
for(j=i+1;j
if(ch2[j].f1
if(k!=i)
{
t=ch2[i].f1;
a=ch2[i].c;
ch2[i].c=ch2[k].c;
ch2[i].f1=ch2[k].f1;
ch2[k].c=a;
ch2[k].f1=t;
}
}
}
Hfptr i