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

100 Most Important C# Programs

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

Code:

#include<stdio.h>

#include<conio.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);

fclose(fp2);

getch( );

}