导航:首页 > 文件处理 > c语言压缩文本文件

c语言压缩文本文件

发布时间:2022-09-25 20:53:36

A. 360压缩怎样压缩C语言程序

1、在c语言文件或存有c语言文件的文件夹上,
右单击鼠标,在弹出的菜单上选择压缩到"xxx.zip"
2、打开360压缩软件,在工具栏上单击添加,选择
c语言文件或文件夹,然后单击工具栏上的一键压缩。

B. 如何用C语言实现数据压缩

首先选择一个压缩算法

然后按照算法实现压缩代码,调用接口就可以
常见的 可以使用哈夫曼编码压缩,或者使用开源的压缩代码,比如lzo, gzip, lzma等等。

C. 在压缩文件中,已得知01二进制编码顺序怎么用C语言写入二进制文件中实现压缩、

我先讲解下压缩的原理,你懂了就知道怎么去实现了。 压缩的原理就是用较短的子串来表示较长的子串。通俗的说比如我发明一种算法将“”可以简化成“50,1”,表示“50个1”,本来50个字的就可以用“50,1”这4个字表示,解压的时候再把“50,1”还原成“”

所以一个bmp图片可以压缩的很厉害,因为有很多重复性的信息,而jpeg在压缩也压缩不了多少,因为没有太多重复性信息。你把一幅全黑的bmp图片可以压缩的很小,而一个色彩斑斓的bmp图片则相对来说压缩处来的文件就会比较大。

D. C语言实现文件压缩

typedef int (WINAPI ICEPUB_COMPRESSFILE)(char *strFilename, char *strZipFilename);
ICEPUB_COMPRESSFILE *icePub_compressFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_compressFile = (ICEPUB_COMPRESSFILE *)GetProcAddress(hDLLDrv, "icePub_compressFile");
}

if(icePub_compressFile)
icePub_compressFile("a.exe","a.Z");

if(hDLLDrv)
FreeLibrary(hDLLDrv);

typedef int (WINAPI ICEPUB_UNCOMPRESSFILE)(char *strZipFilename,char *strFilename);
ICEPUB_UNCOMPRESSFILE *icePub_uncompressFile = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_uncompressFile = (ICEPUB_UNCOMPRESSFILE *)GetProcAddress(hDLLDrv, "icePub_uncompressFile");
}

if(icePub_uncompressFile)
icePub_uncompressFile("a.Z","a.exe");

if(hDLLDrv)
FreeLibrary(hDLLDrv);

E. (20分)用C语言编译的文件压缩解压缩程序

是用霍夫曼树做的
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
struct head
{
unsigned char b; /*the charactor*/
long count; /*the frequency*/
long parent,lch,rch; /*make a tree*/
char bits[256]; /*the haffuman code*/
}
header[512],tmp;

void compress()
{
char filename[255],outputfile[255],buf[512];
unsigned char c;
long i,j,m,n,f;
long min1,pt1,flength;
FILE *ifp,*ofp;
printf("source filename:");
gets(filename);
ifp=fopen(filename,"rb");
if(ifp==NULL)
{
printf("source file open error!\n");
return;
}
printf("destination filename:");
gets(outputfile);
ofp=fopen(outputfile,"wb");
if(ofp==NULL)
{
printf("destination file open error!\n");
return;
}
flength=0;
while(!feof(ifp))
{
fread(&c,1,1,ifp);
header[c].count++;
flength++;
}
flength--;
header[c].count--;
for(i=0;i<512;i++)
{
if(header[i].count!=0) header[i].b=(unsigned char)i;
else header[i].b=0;
header[i].parent=-1;
header[i].lch=header[i].rch=-1;
}
for(i=0;i<256;i++)
{
for(j=i+1;j<256;j++)
{
if(header[i].count<header[j].count)
{
tmp=header[i];
header[i]=header[j];
header[j]=tmp;
}
}
}
for(i=0;i<256;i++) if(header[i].count==0) break;
n=i;
m=2*n-1;
for(i=n;i<m;i++)
{
min1=999999999;
for(j=0;j<i;j++)
{
if(header[j].parent!=-1) continue;
if(min1>header[j].count)
{
pt1=j;
min1=header[j].count;
continue;
}
}
header[i].count=header[pt1].count;
header[pt1].parent=i;
header[i].lch=pt1;
min1=999999999;
for(j=0;j<i;j++)
{
if(header[j].parent!=-1) continue;
if(min1>header[j].count)
{
pt1=j;
min1=header[j].count;
continue;
}
}
header[i].count+=header[pt1].count;
header[i].rch=pt1;
header[pt1].parent=i;
}
for(i=0;i<n;i++)
{
f=i;
header[i].bits[0]=0;
while(header[f].parent!=-1)
{
j=f;
f=header[f].parent;
if(header[f].lch==j)
{
j=strlen(header[i].bits);
memmove(header[i].bits+1,header[i].bits,j+1);
header[i].bits[0]='0';
}
else
{
j=strlen(header[i].bits);
memmove(header[i].bits+1,header[i].bits,j+1);
header[i].bits[0]='1';
}
}
}
fseek(ifp,0,SEEK_SET);
fwrite(&flength,sizeof(int),1,ofp);
fseek(ofp,8,SEEK_SET);
buf[0]=0;
f=0;
pt1=8;
while(!feof(ifp))
{
c=fgetc(ifp);
f++;
for(i=0;i<n;i++)
{
if(c==header[i].b) break;
}
strcat(buf,header[i].bits);
j=strlen(buf);
c=0;
while(j>=8)
{
for(i=0;i<8;i++)
{
if(buf[i]=='1') c=(c<<1)|1;
else c=c<<1;
}
fwrite(&c,1,1,ofp);
pt1++;
strcpy(buf,buf+8);
j=strlen(buf);
}
if(f==flength) break;
}
if(j>0)
{
strcat(buf,"00000000");
for(i=0;i<8;i++)
{
if(buf[i]=='1') c=(c<<1)|1;
else c=c<<1;
}
fwrite(&c,1,1,ofp);
pt1++;
}
fseek(ofp,4,SEEK_SET);
fwrite(&pt1,sizeof(long),1,ofp);
fseek(ofp,pt1,SEEK_SET);
fwrite(&n,sizeof(long),1,ofp);
for(i=0;i<n;i++)
{
fwrite(&(header[i].b),1,1,ofp);
c=strlen(header[i].bits);
fwrite(&c,1,1,ofp);
j=strlen(header[i].bits);
if(j%8!=0)
{
for(f=j%8;f<8;f++)
strcat(header[i].bits,"0");
}
while(header[i].bits[0]!=0)
{
c=0;
for(j=0;j<8;j++)
{
if(header[i].bits[j]=='1') c=(c<<1)|1;
else c=c<<1;
}
strcpy(header[i].bits,header[i].bits+8);
fwrite(&c,1,1,ofp);
}
}
fclose(ifp);
fclose(ofp);
printf("compress successfully!\n");
return;
}
void uncompress()
{
char filename[255],outputfile[255],buf[255],bx[255];
unsigned char c;
long i,j,m,n,f,p,l;
long flength;
FILE *ifp,*ofp;
printf("source filename:");
gets(filename);
ifp=fopen(filename,"rb");
if(ifp==NULL)
{
printf("source file open error!\n");
return;
}
printf("destination filename:");
gets(outputfile);
ofp=fopen(outputfile,"wb");
if(ofp==NULL)
{
printf("destination file open error!\n");
return;
}
fread(&flength,sizeof(long),1,ifp);
fread(&f,sizeof(long),1,ifp);
fseek(ifp,f,SEEK_SET);
fread(&n,sizeof(long),1,ifp);
for(i=0;i<n;i++)
{
fread(&header[i].b,1,1,ifp);
fread(&c,1,1,ifp);
p=(long)c;
header[i].count=p;
header[i].bits[0]=0;
if(p%8>0) m=p/8+1;
else m=p/8;
for(j=0;j<m;j++)
{
fread(&c,1,1,ifp);
f=c;
itoa(f,buf,2);
f=strlen(buf);
for(l=8;l>f;l--)
{
strcat(header[i].bits,"0");
}
strcat(header[i].bits,buf);
}
header[i].bits[p]=0;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strlen(header[i].bits)>strlen(header[j].bits))
{
tmp=header[i];
header[i]=header[j];
header[j]=tmp;
}
}
}
p=strlen(header[n-1].bits);
fseek(ifp,8,SEEK_SET);
m=0;
bx[0]=0;
while(1)
{
while(strlen(bx)<(unsigned int)p)
{
fread(&c,1,1,ifp);
f=c;
itoa(f,buf,2);
f=strlen(buf);
for(l=8;l>f;l--)
{
strcat(bx,"0");
}
strcat(bx,buf);
}
for(i=0;i<n;i++)
{
if(memcmp(header[i].bits,bx,header[i].count)==0) break;
}
strcpy(bx,bx+header[i].count);
c=header[i].b;
fwrite(&c,1,1,ofp);
m++;
if(m==flength) break;
}
fclose(ifp);
fclose(ofp);
printf("Uncompress successfully!\n");
return;
}
int main()
{
int c;
printf("1--Compress file\n");
printf("2--Uncompress file\n");
printf("Select 1 or 2:");
c=getch();
printf("%c\n",c);
if(c=='1') compress();
else if(c=='2') uncompress();
return 0;
}

F. 用C语言如何对文件进行压缩

winrar软件安装后,所在的安装目录下有个rar.exe,开一个命令窗口到该目录下运行rar
/?就能看到用法了,在你的程序里面调用它的相应命令行是最简单的方法,自己编写压缩算法的话,先不谈效率,起码算法就是相当复杂的了

G. 如何用C语言解压缩文件

如果你自己设计算法,就另当别论,如果想利用第3方的算法,我推荐用zlib,生成的压缩包是流行的zip格式.源代码很好找(www.zlib.net)

阅读全文

与c语言压缩文本文件相关的资料

热点内容
简单的游戏代码源码 浏览:345
金蝶服务器怎么改 浏览:594
h y p 6.vip 浏览:709
韩国战争电影十大巅峰之作 浏览:425
大尺度百合剧 浏览:112
为什么要叫毒app 浏览:492
编程类校赛 浏览:994
五十五度灰 浏览:351
android入门到精通pdf明日科技 浏览:491
解压缩文件怎么老重启 浏览:213
儿童智能关怀app苹果为什么不能用 浏览:707
tcpdump抓包命令 浏览:793
各大主播在用什么app看电影 浏览:421
泰国恐怖片 和尚 浏览:219
宁夏品质压缩机市场 浏览:186
日立螺杆压缩机维修 浏览:427
识别英语单词哪个app比较好 浏览:188
夫人被家丁强奸的泰国电影? 浏览:256
书香门第小说txt下载 浏览:454