programming-examples/c/Data_Input_Output/C Program to Concate two file into third file.c

35 lines
740 B
C
Raw Normal View History

2019-11-15 12:59:38 +01:00
#include<stdio.h>
#include<stdlib.h>
void main()
{
FILE *fp1,*fp2,*fp3;
char ch;
int tc=0,tw=1;
fp1=fopen("file1.txt","r");
if(fp1==NULL)
{
printf("File doesn't exist\n");
exit(1);
}
fp2=fopen("file2.txt","r");
if(fp2==NULL)
{
printf("File doesn't exist\n");
exit(1);
}
fp3=fopen("file3.txt","w");
while(!feof(fp1))
{
ch=getc(fp1);
putc(ch,fp3);
}
fclose(fp1);
while(!feof(fp2))
{
ch=getc(fp2);
putc(ch,fp3);
}
fclose(fp2);
fclose(fp3);
printf("file1 and file2 are concatenated in file3")
}