#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <memory.h>
int main(void)
{
FILE *fd1 = NULL;
FILE *fd2 = NULL;
FILE *fd = NULL;
//以二进制方式打开第一个及第二个文件读,以二进制方式打开第三个文件写
fd1 = fopen("1.txt", "rb");
fd2 = fopen("2.txt", "rb");
fd = fopen("3.txt", "wb");
//获取第一个及第二个文件的大小
int fn1 = fileno(fd1);
long fsize1 = filelength(fn1);
int fn2 = fileno(fd2);
long fsize2 = filelength(fn2);
//申请内存缓冲区保存第一个文件及第二个文件读取到的内容
char *buf1 = new char[fsize1];
memset(buf1,0x0,fsize1);
char *buf2 = new char[fsize2];
memset(buf2,0x0,fsize2);
//读第一个文件及第二个文件后关闭第一个及第二个文件后,关闭此两个文件
fread(buf1,fsize1,1,fd1);
fread(buf2,fsize2,1,fd2);
fclose(fd1);
fclose(fd2);
//将第一个文件及第二个文件的内容写到第三个文件中后,关闭第三个文件
fwrite(buf1,fsize1,1,fd);
fwrite(buf2,fsize2,1,fd);
fclose(fd);
//删除申请的内存
delete[] buf1;
delete[] buf2;
return 0;
}
温馨提示:答案为网友推荐,仅供参考