C语言编程题,求助大神!

编写程序,实现两个已知文本文件内容(每个文件中有一行字符串)的连接并将连接内容保存在一个新文件中。

第1个回答  2020-06-16

#include <stdio.h>

#include <string.h>

#define N 10000

int main()

{

FILE *fp1,*fp2,*fp3;

char str1[N],str2[N];

fp1=fopen("D:\\666.txt","r");

fp2=fopen("D:\\888.txt","r");

fp3=fopen("D:\\999.txt","w");

while(fgets(str1,N,fp1)!=NULL)//将文件中的每一个非空字符储存在数组str1中 

while(fgets(str2,N,fp2)!=NULL)//同上 

puts(str1);//输出文件的内容 

puts(str2);

strcat(str1,str2);//两个字符串连接 

fprintf(fp3,"%s",str1);//将连接后的字符串写入第3个文件 

fclose(fp1);//关闭文件 

fclose(fp2);

fclose(fp3);

return 0;

}

本回答被提问者采纳