#include <stdio.h>
#include <string.h>
#include <conio.h>
struct fileINFO
{
char filename[20];
int filelen;
};
char ysb[20];
struct fileINFO tempname;
int getfilelen(char name[])
{
FILE *fp;
char ch;
int len=0;
fp=fopen(name,"r");
while(1)
{
ch=fgetc(fp);
if(feof(fp))
{
break;
}
len++;
}
fclose(fp);
return len;
}
void filleys(void)
{
FILE *ysfp,*rfp;
int i;
char ch;
printf("请输入压缩包文件名");
scanf("%s",ysb);
ysfp=fopen(ysb,"w");
if(ysfp==NULL)
{
printf("文件打开失败\n");
return;
}
else
{
printf("请输入待压缩文件,以exit结束\n");
while(1)
{
scanf("%s",tempname.filename);
if(strcmp(tempname.filename,"exit")==0)
{
break;
}
tempname.filelen=getfilelen(tempname.filename);
rfp=fopen(tempname.filename,"r");
fwrite(&tempname,sizeof(tempname),1,ysfp);
if(rfp!=NULL)
{
for(i=0;i<tempname.filelen;i++)
{
ch=fgetc(rfp);
fputc(ch,ysfp);
}
}
fclose(rfp);
}
}
fclose(ysfp);
}
void filejy(void)
{
FILE *fp,*wfp;
char ch;
int i;
printf("请输入压缩包文件名");
scanf("%s",ysb);
fp=fopen(ysb,"r");
if(fp==NULL)
{
printf("文件打开失败\n");
return;
}
else
{
while(1)
{
fread(&tempname,sizeof(tempname),1,fp);
if(feof(fp))
{
break;
}
wfp=fopen(tempname.filename,"w");
if(wfp!=NULL)
{
for (i=0;i<tempname.filelen;i++)
{
ch=fgetc(fp);
fputc(ch,wfp);
}
}
fclose(wfp);
}
}
fclose(fp);
}
void delfile(void)
{
char name[20];
printf("请输入需要删除的文件名\n");
scanf("%s",name);
if(remove(name))
{
printf("文件不存在,删除失败\n");
return;
}
else
{
printf("文件删除成功\n");
}
}
void main(void)
{
char ch;
while(1)
{
printf("1.压缩文件\n");
printf("2.解压文件\n");
printf("3.删除文件\n");
ch=getch();
switch(ch)
{
case '1':
filleys();
break;
case '2':
filejy();
break;
case '3':
delfile();
break;
}
}
}
#include <stdio.h>
#include <string.h>
#include <conio.h>
struct fileINFO
{
char filename[20];
int filelen;
};
char ysb[20];
struct fileINFO tempname;
int getfilelen(char name[])
{
FILE *fp;
char ch;
int len=0;
fp=fopen(name,"r");
while(1)
{
ch=fgetc(fp);
if(feof(fp))
{
break;
}
len++;
}
fclose(fp);
return len;
}
viod fileys(viod)
{
FILE *ysfp,*rfp;
int i;
char ch;
printf("请输入压缩包文件名");
scanf("%s,ysb");
ysfp=fopen(ysb,"w");
if(ysfp==NULL)
{
printf("文件打开失败\n");
return;
}
else
{
printf("请输入压缩文件,·以exit结束\n");
while(1)
{
scanf("%s",tempname.filename);
if(strcmp(tempname.filename,"exit")==0)
{
break;
}
tempname.filelen=getfilelen(tempname.filename);
rfp=fopen(tempname,sizeof(tempname),1,ysfp);
if (rfp!=NULL)
{
for (i=0;i<tempname.filename;i++)
{
ch=fgetc(rfp);
fputc(ch,ysfp);
}
}
}
}
}