Program to copy the contents of one file into another using fgetc and fputc function
#include<stdio.h>
#include<process.h>
void main()
{
FILE *fp1,*fp2;
char a;
clrscr();
fp1=fopen("test.txt","r");
if(fp1==NULL)
{
puts("cannot open this file");
exit(1);
}
fp2=fopen("test1.txt","w");
if(fp2==NULL)
{
puts("Not able to open this file");
fclose(fp1);
exit(1);
}
do
{
a=fgetc(fp1);
fputc(a,fp2);
}while(a!=EOF);
fcloseall();
getch();
}
Output :
Content will be written successfully to file
About the author: Pritesh View all posts by Pritesh
My name is Pritesh Taral. I am working in well known MNC. as Java Developer. I am part time blogger loves writing articles on C/C++.
I am active on facebook using community fan page .One can Visit me @ Facebook
Facebook Fan Page