Q:

C PROGRAM TO COPY CONTENT OF ONE FILE TO ANOTHER:

0

C PROGRAM TO COPY CONTENT OF ONE FILE TO ANOTHER:

Below C program is used to copy the content of one file into another.

If you want to add error handling on file operation such as fopen(), fclose()

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
int main()
 
{
 
   char ch;
 
   FILE *fp1;
 
   FILE *fp2;
 
   /* Assume this test1.c file has some data.
 
      For example “Hi, How are you?” */
 
   if (fp1 = fopen("test1.c", "r"))
 
   {
 
      ch = getc(fp1);
 
      // Assume this test2.c file is empty
 
      fp2 = fopen("test2.c", "w+")
 
      while (ch != EOF)
 
      {
 
         fputc(ch, fp2);
 
         ch = getc(fp1);
 
      }
 
      fclose(fp1);
 
      fclose(fp2);
 
      return 0;
 
   }
 
   return 1;
 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now