Sunday, April 5, 2020

Copy Content Of One File To Another | C Programming Example

C Program Example For To Copy Content Of One File To Another


This Article From Learn c programming in Hindi Will help you to learn To Copy Content Of One File To Another, C programming language Example and check out "selection sort program in c", "socket programming in c", "merge sort program in c","Kruskal's algorithm in c", "for loop c programming", "c struct example","simple program in c language", "simple CPP program", "c programming practice questions", "c program using for loop", "programming using c", "hello world program in c", "if statement in c ".


C program Example
C program Example




नीचे C Program Example का उपयोग एक फ़ाइल की सामग्री को दूसरे में कॉपी करने के लिए किया जाता है। यदि आप फ़ाइल संचालन जैसे fopen (), fclose () पर Error Handling जोड़ना चाहते हैं, 

Source Code 

#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;
 
}

0 Comments:

Post a Comment