C program to copy text from one file to other file

C program to copy text from one file to other file:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
#include<stdlib.h>

main()
{
   FILE *fp1,*fp2;
   char ch;

   fp1 = fopen("input.txt","r"); //Accepting input file name
   fp2 = fopen("output.txt","w"); //Accepting output file name

   while(1)
    {
      ch=fgetc(fp1);

      if(ch == EOF)
        break;
      else
        putc(ch,fp2);
    }

   printf("File copied Successfully!");
   fclose(fp1);
   fclose(fp2);
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

14 − 1 =