source file name: FileCopy.C
Requirement of aboutsjn.txt file exists
#include<stdio.h>
int main()
{
int n;
char ch;
FILE *fp1,*fp2;
//clrscr();
fp1=fopen("aboutsjn.txt","r");
fp2=fopen("copy1.txt","w");
while((ch=fgetc(fp1))!=EOF)
{
fprintf(fp2,"%c",ch);
}
fclose(fp2);
fclose(fp1);
fp1=fopen("aboutsjn.txt","r");
fp2=fopen("copy1.txt","r");
printf("\n Contents of File one\n ");
while((ch=fgetc(fp1))!=EOF)
{
printf("%c",ch);
}
printf("\n Contents of File second\n ");
while((ch=fgetc(fp2))!=EOF)
{
printf("%c",ch);
}
fclose(fp1);
fclose(fp2);
//getch();
return 0;
}
output:
2 Comments
Very useful!
ReplyDeleteThanks you are welcome
DeletePost a Comment