当前位置:首页 » 文件管理 » 压缩编写

压缩编写

发布时间: 2022-08-05 15:58:27

‘壹’ 如何编写数据压缩系统

那么有两种情况,1是第三方的文件,2是自身程序
也不是绝对不能做到,能做到但是效果不好,并且也十分复杂.
主要思路说说吧
利用Hook来监视文件操作,更高级的方式是监控硬盘的操作,需要有个常驻内存的程序来监控,就象360等一样,
但这样的话别人随便用什么PE进入系统,监视就无效了
自身程序想防止拷贝和压缩很难做到,至少我还没有这方面的思路,因为所有软件都是以数据形式存储在硬盘中的,它本身就是一段数据,除了使用外部程序的控制,按照目前的存储技术很难做到自防止.这也是目前盗版较容易的原由所在.也因此各种软件采取了注册码,网上验证方式来防止程序的共享.
不好意思,这个技术很难,恐怕得从存储机理上下功夫,如果被发明出来,可能会引发全球的存储技术的革新,目前也没有其他好的方法.
另外,虚机团上产品团购,超级便宜

‘贰’ 如何用VB编写压缩与解压缩的程序

自己编写一个好的压缩与解压缩程序,算法是相当复杂的,如果只是想把多个文件打个包并不难,把多个文件写入一个二进制文件即可,当然这里面也要有文件名如何保存,每个文件到哪结束等的问题。
最简单的方法是调用第三方软比如zip等,建议调用ARJ.EXE或LHARC.EXE因为它们只一个文件并且体积都很小压缩比也不错。

‘叁’ 如何用C语言编写一个简单的压缩程序

觉得难度够大了,谈谈我的方法吧:比如字符串"aabbccddeeffgg123456789"可以看到里面有字母重复,并且有规律,是否可以表示成2a to 2g 1 to 9?因该可以的,数据压缩的原理也都是把冗余的数据简化表示从而减少数据的大小,解压时就是反向过程,但是怎么完整表示这些被压缩的数据就是个要研究的问题。

‘肆’ 我能自己编写压缩代码吗不用压缩工具来进行

这是用是用霍夫曼树做的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;
}

‘伍’ 怎么编写bat文件,对文件夹进行压缩

@echo off

set rar="%ProgramFiles%\WinRAR\winrar.exe"
%rar% a -afzip -r -ep1 "D:\a\b" "5.zip"

‘陆’ 请问用C语言怎么编写压缩软件啊

二大要点:
一、文件操作:
打开需要压缩的原文件并读取之;
新建写入的压缩文件写入之;

二、压缩算法

‘柒’ C语言求助:请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。

#include <stdio.h>

void stringZip(const char

*pInputStr, long lInputLen, char *pOutputStr)

{ int n=1;

char c,*p1=pInputStr,*p2=pOutputStr;

while(*p1)

{

c=*(p1++);

while(*p1==c){n++;p1++;}

if(n>1)

{

if(n>999){*(p2++)=48+n/1000; n/=10;}

if(n>99){*(p2++)=48+n/100; n/=10;}

if(n>9){*(p2++)=48+n/10; n/=10;}

*(p2++)=48+n;

}

*(p2++)=c;

n=1;

}

*p2='';

}

void main()

{ char s1[200],s2[200];

gets(s1);

stringZip(s1,strlen(s1),s2);

puts(s2);

}

‘捌’ 用C语言如何对文件进行压缩

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

热点内容
h5调查问卷源码 发布:2025-05-07 07:35:47 浏览:309
批6200是个什么服务器 发布:2025-05-07 07:34:21 浏览:871
我的世界决战斗罗服务器如何进入 发布:2025-05-07 07:28:38 浏览:993
sql视图使用 发布:2025-05-07 07:25:50 浏览:153
文件压缩单位 发布:2025-05-07 07:25:45 浏览:791
pythonyield与return 发布:2025-05-07 07:24:05 浏览:131
json上传图片 发布:2025-05-07 07:06:13 浏览:861
第一次使用微信支付密码如何设定 发布:2025-05-07 06:57:16 浏览:817
帮助文档网站源码 发布:2025-05-07 06:57:10 浏览:97
linuxmysql数据库重启 发布:2025-05-07 06:50:24 浏览:522