/*** 文档合并 ***/
/*** 运行程式时,假如编绎成的可执行文档名为fadd.exe 则 命令行:例如 fadd file#nnn 主意:输入" file#nnn " ,而不是 " file#nnn.001 " ***/ /*** 当分快文档少于 32 块时,能够不用此程式, 直接运行分割时生成的披拷贝文档即可 ***/
#include<sio.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'; scat (fn_in,p); len=slen (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==0&&pc_fn0!=0) { *(fn_in len-2) =1; *(fn_in len-1)-=9; } else if (pc_fn0!=0) *(fn_in len-1) =1; if (pc_fn0==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); } 文章来源: 电脑软件教程下载库
|