[C语言] 文件操作,合并两个二进制文件为单独一个二进制文件;

#define BUFFER_SIZE 1024

//
合并文件mergeFile (infile1, infile2, filenmae) void mergeFile(FILE *fp1,FILE *fp2,char *name){ FILE *fd1,*fd2,*fp3; unsigned char buf[BUFFER_SIZE]; char filename[100]; strncpy(filename,name,sizeof(filename)); int rc1,rc2; fd1 = fopen(fp1,"rb"); fd2 = fopen(fp2,"rb"); fp3 = fopen(filename, "wb" ); while( (rc1 = fread(buf,sizeof(unsigned char), BUFFER_SIZE,fd1)) != 0 ) { fwrite( buf, sizeof( unsigned char ), rc1, fp3 ); } while( (rc2 = fread(buf,sizeof(unsigned char), BUFFER_SIZE,fd2)) != 0 ) { fwrite( buf, sizeof( unsigned char ), rc2, fp3 ); } sleep(0.1); fclose(fd1); fclose(fd2); fclose(fp3); }
------------
微博:http://weibo.com/scue
Github:http://github.com/scue
原文地址:https://www.cnblogs.com/scue/p/2983855.html