文件分割与合并程序

#include "dos.h"
#include "stdio.h"
#include "conio.h"
#include
FILE *fp,*fp1,*fp2,*fp3,*fp4,*fp5,*fp6;
char ch3[50];
void postfixname(int divnum)
{     struct ffblk ffblk1;
   int j,ch1[3],done;
   char fixname[4]=".",changename[3];
     for(j=0;j<3;j++)
   {
      ch1[j]=divnum%10;
      divnum=divnum/10;
   }
   for(j=2;j>-1;j--)
   {
      itoa(ch1[j],changename[j],10);
      strcat(fixname,changename[j]);
   }
   strcat(ch3,fixname);
}
void getfname(char *savename)
{
  int i;
  char firstname[20];

  for(i=0;i<20;i++)
  {
     if(savename[i]=='.')
     break;
     firstname[i]=savename[i];

  }
  firstname[i]='/0';
  strcpy(savename,firstname);
}
void division(int divnum)
{
     struct ffblk ffblk;
     struct ffblk ffblk1;
   long int fsize,done,done1,divnum1=1,everysize,leftsize;
   int ch1[3],j;
   float i=0,countsize=0;
   unsigned char *ch2="D://Win-TC//pro1//pro//",ch,lastname;
   char *ch4="D://Win-TC//pro1//pro//record.xx",savename[20];
   done=findfirst("D://Win-TC//pro1//tea1.bmp",&ffblk,0);/*指针指向所要分割的文件*/
   strcpy(savename,ffblk.ff_name);
   getfname(savename);
   printf("%s",savename);
   fsize=ffblk.ff_fsize;
   everysize=fsize/divnum;
   leftsize=fsize%divnum;
   fp=fopen("D://Win-TC//pro1//tea1.bmp","rb");/*指针指向所要分割的文件*/
   fp3=fopen("D://Win-TC//pro1//pro//record.xx","wb");/*创建一个文件并写入*/
   if(fp==NULL)
   {
      printf("sorry");
      getch();
   }
while(divnum1<=divnum+1)
{
   fseek(fp,countsize, SEEK_SET);
   strcpy(ch3,ch2);
   strcat(ch3,savename);
   postfixname(divnum1);
   fp1=fopen(ch3,"wb");/*创建一个文件并写入*/
   if(fp1==NULL)
   {
      printf("error!");
      exit(0);
   }
   ch=fgetc(fp);
   while(!feof(fp)&&i   {
      fputc(ch,fp1);   
      ch=fgetc(fp);
      if(feof(fp))
      break;
      i++;
   }
   countsize=countsize+everysize;
   i=0;
   divnum1++;
   fclose(fp1);/*关闭已复制完的文件*/
   done1=findfirst(ch3,&ffblk1,0);
   fp3=fopen("D://Win-TC//pro1//pro//record.xx" ,"a+");
   strlen(ch3);
   fprintf(fp3,"%s/n%ld/n",ch3,ffblk1.ff_fsize);
   fclose(fp3);
}
   fclose(fp);/*关闭已复制完的文件*/
}
void combin()
{
   int fnamesize,fsize1,countsize=0;
   char ch5[50],ch;
   fp4=fopen("D://Win-TC//pro1//pro//record.xx","rb");/*打开分割文件的记录*/
   fp5=fopen("D://Win-TC//pro1//pro//tea1.bmp","wb"); /*存储合并成的文件*/
while(!feof(fp4))
{


   fscanf(fp4,"%s",ch5);
   if(feof(fp4))break;
   fscanf(fp4,"%d",&fsize1);
   fp6=fopen(ch5,"rb");
      ch=fgetc(fp6);
   while(!feof(fp6))/*写入过程*/
   {
      fputc(ch,fp5);
      ch=fgetc(fp6);
      if(feof(fp6))break;
   }
   fclose(fp6);
   printf("%s,%d/n",ch5,fsize1);
}
fclose(fp4);
fclose(fp5);
}
void main()
{
   int divnum=300-1;/*分割文件数目*/
   division(divnum);
   combin();
   getch();
}

你可能感兴趣的:(心得文摘)