C/C++ 二进制 追加读写文件
#include <stdio.h> //标准输入输入出的头文件,printf和scanf都在这里了
#include <stdlib.h> //标准库头文件,内存分配、数学运算等都在这里了
//如果为非二进制文件,不加fopen的参数选项"b"即可了
#define MAXLEN 1024
int main()
{
int rc;
FILE * outfile, *infile;
int i = 0;
for(i =0; i<=45; i++) {
char fileopen[15] = {0};
sprintf(fileopen,"222.rmvb_%d.!mv",i);
outfile = fopen("222.rmvb", "ab" );//追加
infile = fopen(fileopen, "rb");
unsigned char buf[MAXLEN];
if( outfile == NULL || infile == NULL ) {
exit(1);
}
while( (rc = fread(buf,sizeof(unsigned char),MAXLEN,infile)) != 0 ) {
fwrite( buf, sizeof( unsigned char ), rc, outfile );
}
fclose(infile);
fclose(outfile);
}
return 0;
}