C Program to Copy Content of One File into Another File

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Program for copy one file into other
#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp1,*fp2;
    char ch;
    fp1=fopen("E://CData/employee.txt","r");
    fp2=fopen("E://CData/newemp.txt","w");
    if(fp1==NULL || fp2==NULL)
        printf("File Error.....");
     else
     {
        do
        {
            ch=fgetc(fp1);
            fputc(ch,fp2);
        }while(ch!=EOF);
       fclose(fp1);
       fclose(fp2);
       printf("\nFile copied successfully.......");
     }   
    
}

 

Did you like this article? If Yes, please give DataFlair 5 Stars on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

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