Write a C program to copy contents of one file to another file.

C File =>

/* Write a C program to copy contents of one file to another file. */


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main() {
      FILE *fp1,*fp2;
      char ch;
      fp1=fopen("a.txt","r");
      fp2=fopen("b.txt","w");
      if(!fp1)
             printf("\n Error in reading..");
      if(!fp2)
             printf("\n Error in writing..");
      else
     {
          while((ch=fgetc(fp1))!=EOF)
               fputc(ch,fp2);
      }
    return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.