Program to copy contents of one file into anothe - 100 Most Important C# Programs

94. Program to copy contents of one file into another.

Code:

#include<conio.h>

#include<stdio.h>

main( )

{

FILE * fp1,*fp2;

char ch;

fp1=fopen(“text1”,”w”);

printf(“enter the text”);

while((ch=getchar()!=EOF);

putc(ch,fp1);

fclose(fp1);

fp1=fopen(“text1”,”r”);

fp2=fopen(“text2”,”w”);

while((ch=getc(fp1))!=EOF)

putc(ch,fp2);

fcolse(fp1);

fcolse(fp2);

getch( );

}