Write a c program to copy & count the character content of one file says a.txt to another file b.txt.

 Code:-

#include<stdio.h>
FILE *fp,*ft;

int main()
{
int count=0;
char ch;
fp=fopen(“a.txt”,“r”);
ft=fopen(“b.txt”,“w”);
if(fp==NULL || ft==NULL)
printf(“File is unable to openn”);
else
{
while((ch=fgetc(fp))!=EOF)
{
fputc(ch,ft);
count++;
}
}
// It is important to close the file after operation
fclose(fp);
fclose(ft);
printf(“The number of character is : %d”,count);
return 0;
}

Output:-

 File “a.txt” has content:-

This is easycodingzone and you can learn programming in a easyway.

The number of charater is : 65


After running the code File “b.txt ” has content:-

This is easycodingzone and you can learn programming in a easyway.




Leave a Reply

Your email address will not be published.