c语言文件,怎么把前面的文件的内容追加搭配后面文件内容

#include<stdio.h>
#include<stdlib.h>
int main()
{
 FILE *fp;
 FILE *fp1;
 char ch;
 char ch1;
 if((fp=fopen("file1.txt","w"))==NULL)
 {
  printf("cannot open this file!\n");
  exit(0);
 }
 
 while((ch=getchar())!='\n')
  fputc(ch,fp);
 fclose(fp);
 
 /*if((fp=fopen("file1.txt","r"))==NULL)
 {
  printf("cannot open this file!\n");
  exit(0);
 }

 while((ch=fgetc(fp))!=EOF)
  putchar(ch);
 fclose(fp);*/
 
 if((fp1=fopen("file2.txt","w"))==NULL)
 {
  printf("cannot open this file2!\n");
  exit(0);
 }
 
 while((ch1=getchar())!='\n')
  fputc(ch1,fp1);
 fclose(fp1);
 
 /*if((fp1=fopen("file2.txt","r"))==NULL)
 {
  printf("cannot open this file2!\n");
  exit(0);
 }
 
 while((ch1=fgetc(fp))!=EOF)
  putchar(ch1);
 fclose(fp1);*/
 
 
 
 return 0;
}


清_醒
浏览 1803回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP