打開兩個已存在的文件 file1 和 file2,並將 file2 拼接到 file1 的後面。
#include<stdio.h>
#define SIZE 30
int main(){
FILE *fp1,*fp2;
if((fp1 = fopen("file1","a+"))== NULL){
printf("Cannot open file1! \n");
return 0;
}
if((fp2 = fopen("file2","r")) == NULL){
printf("Cannot open file2! \n");
return 0;
}
while(!feof(fp2))
// 把 fp2 追加到 fp1
fputc(fp2, fp1);
fclose(fp1);
fclose(fp2);
}