/***
运行程序时,假如编绎成的可执行文件名为fadd.exe
则 命令行:例如 fadd file#nnn
主意:输入" file#nnn " ,而不是 " file#nnn.001 " ***/
/*** 当分快文件少于 32 块时,可以不用此程序,
直接运行分割时生成的披拷贝文件即可 ***/
#include<stdio.h>
main(int argc,char **argv)
{
FILE *fp_read,*fp_write;
int buffer=0,i,len,pc_fn=1;
char *fn_in,fn_out[50],*p=".001",ch='#';
if (argc==1)
{
printf ("\n ERROR! you fogot enter the file name ( file#nnn )\n");
exit (0);
}
fn_in=argv[1];
i=0; /*** file#nnn ---> file.nnn 得到目标文件名 ***/
while (*(fn_in+i))
{
if (*(fn_in+i)=='#') *(fn_out+i)='.'; else *(fn_out+i)=*(fn_in+i); i++;
}
*(fn_out+i)='\0';
strcat (fn_in,p); len=strlen (fn_in); /*** file#nnn ---> file#nnn.01 ***/
if ((fp_read=fopen (fn_in,"rb"))==NULL) /*** 检测块文件是否存在***/
{ printf ("\n ERROR! the file \" %s \" not exsits\n",fn_in); exit (0); }
/*** 检测目标文件是否已经存在。假如存在,交出"控制权" ***/
if ((fp_write=fopen(fn_out,"rb"))!=NULL)
{
fclose (fp_write);
printf ("\n OVERWRITE the file \" %s \" (Y/N)?",fn_out);
while (ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y')
{
ch=getche();
if (ch=='Y'||ch=='y') break;
if (ch=='N'||ch=='n') { printf ("\n"); exit (0); }
}
printf ("\n");
}
/*** 合并 ***/ /*** 第一个块文件已在前面检测时打开 ***/
fp_write=fopen(fn_out,"wb"); /*** 建立目标文件 ***/
while (fp_read) /*** 块文件不能被打开 (不存在 ) 时,停下 ***/
{
fread (&buffer,1,1,fp_read);
while (!feof(fp_read))
{
fwrite (&buffer,1,1,fp_write); fread (&buffer,1,1,fp_read);
}
fclose (fp_read);
pc_fn++;
if (pc_fn%10==0&&pc_fn%100!=0)
{ *(fn_in+len-2)+=1; *(fn_in+len-1)-=9; }
else if (pc_fn%100!=0) *(fn_in+len-1)+=1;
if (pc_fn%100==0) { *(fn_in+len-3)+=1; *(fn_in+len-2)-=9; *(fn_in+len-1)-=9; }
fp_read=fopen(fn_in,"rb");
}
fclose (fp_read); fclose (fp_write);
printf ("\n OK! the file \" %s \" be created successfuly\n",fn_out);
printf ("\n %d files been added\n",pc_fn-1);
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |