This program takes the contents of a text file and copies them into another text file character by character.
Example 2:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
char ch;
FILE *fs, *ft;
fs=fopen(“file1.txt”,”r”);
if(fs=NULL)
{
printf(“Cannot open source file”);
exit(1);
}
ft=fopen(“file2.txt”,”w”);
if(ft==NULL)
{
prntf(“Cannot open target file”);
fclose(fs);
exit(1);
}
while ((ch=fgetc(fs))!=EOF)
fputc(ch,ft);
fclose(fs);
fclose(ft);
getch();
}
In this program file1.txt is a source file which is opened in read mode and file2.txt is a destination file which is opened in write mode.
No Comments