实在是没着拉
一个机子一个运行结果!!
关键那个机子的运行结果都不对
程序介绍:这个程序运用是最简单的压缩方法,数据:2222压缩成 4 2 分成2个文件分装
这种方法处理完成后再连接两个文件(这一部我的程序没有写)
源程序:
#include <stdio.h>
int reduce(char *file_name); /*压缩一个文件*/
int dell_fill(char *file1_name,char *file2_name);/*删除两个文件*/
int re_file(char *file1_name,char *file2_name);/*解压缩两个文件*/
main()
{
char *file_name="E:\\file.txt";
reduce(file_name);
puts("\nend!");
getch();
}
int reduce(char *file_name)
{
FILE *fp,*fp1,*fp2;
long fnum=0;
int f=0,f_h=1,flag,i;
char *file1_name,*file2_name;
if((fp=fopen(file_name,"rb"))==NULL)
{
printf("Open the \"%s\" error!",file_name);
getch();
exit(1);
}
i=0;
flag=0;
do
{
if(file_name[i]=='.')
{
file1_name[i]='a';
file1_name[i+1]='.';
file2_name[i]='b';
file2_name[i+1]='.';
flag=1;
}
else
{
file1_name[i+flag]=file_name[i];
file2_name[i+flag]=file_name[i];
}
}while(file_name[i++]!=0);
if(!flag)
{
file1_name[i]='a';
file2_name[i]='b';
}
if((fp1=fopen(file1_name,"w+"))==NULL)
{
printf("Creat the \"%s\" error!",file1_name);
getch();
exit(1);
}
if((fp2=fopen(file2_name,"w+"))==NULL)
{
printf("Creat the \"%s\" error!",file2_name);
getch();
exit(1);
}
f_h=fgetc(fp);
while(f!=-1)
{
f=fgetc(fp);
if(f_h==f)
{
fnum++; /*解除长整形限制*/
}
else
{
do
{
fputc(fnum%256,fp1);
fputc(f_h,fp2);
}while(fnum/=256);
fnum=0;
}
f_h=f;
}
fclose(fp);
fclose(fp1);
fclose(fp2);
re_file(file1_name,file2_name);
dell_fill(file1_name,file2_name);
}
int dell_fill(char *file1_name,char *file2_name)
{
unlink(file1_name);
unlink(file2_name);
}
int re_file(char *file1_name,char *file2_name)
{
FILE *fp,*fp1,*fp2;
int f=0,f_h,i,flag;
char *file_name;
if((fp1=fopen(file1_name,"rb"))==NULL)
{
printf("Creat the \"%s\" error!",file1_name);
getch();
exit(1);
}
if((fp2=fopen(file2_name,"rb"))==NULL)
{
printf("Creat the \"%s\" error!",file2_name);
getch();
exit(1);
}
i=0;
flag=0;
do
{
if(file1_name[i]=='.')
{
file_name[i-1]='.';
flag=-1;
}
else
file_name[i+flag]=file1_name[i];
}while(file1_name[i++]!=0);
if(!flag)
file_name[i-1]=0;
if((fp=fopen("E:\\fil.txt","wt"))==NULL)
{
printf("Creat the \"%s\" error!",file_name);
getch();
exit(1);
}
while(f!=-1)
{
f=fgetc(fp1);
f_h=fgetc(fp2);
for(i=0;i<=f;i++)
{
fputc(f_h,fp);
}
}
fclose(fp);
fclose(fp1);
fclose(fp2);
}