To copy text from one file to another file > C Program

To copy text from one file to another file > C Program

System Programming and Compiler Construction


#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1, *fp2;
char ch, fname1[20], fname2[20];

printf("\nENTER THE SOURCE FILE NAME:");
gets(fname1);
printf("\nENTER DESTINATION FILE NAME:");
gets(fname2);
fp1 = fopen(fname1,"r");
fp2 = fopen(fname2,"w");
if(fp1==NULL || fp2==NULL)
{
printf("UNABLE TO OPEN");
exit(0);
}
do
{
ch = fgetc(fp1);
if(ch!=EOF)
fputc(ch,fp2);

}while (ch!=EOF);

fcloseall();
getch();
}

NOTE: Make sure that files are in same folder as C Program

Comments

Popular posts from this blog

Intermediate Code Generation > C Program