C Programming File Handling | Copying one file to Another *file

Write a Modular C Programming code for Copying one file to Another *file

*The file should be saved in (1.txt & copy.txt) this Format in the location of this c file.
Below is the content of File:

FactsPrime has helped me in learning c-programming! 

Refer To Notes:  Notes: File Handling in C programming | Operations in Files



void file_copy(FILE *, FILE *);

int main()
    FILE *fp1, *fp2;
    fp1 = fopen("1.txt","r");
    fp2 = fopen("copy.txt","w");
    if(fp1==NULL || fp2==NULL)
        perror("");//same as printf, but perror will print compiler error message as well
    file_copy(fp1, fp2);
    return 0;

void file_copy(FILE *fp1, FILE *fp2)
    char ch;
        putc(ch, fp2);


This will copy the content of file 1.txt to the copy.txt file. And saves it.

Process returned 0 (0x0)   execution time : 369.409 s
Press any key to continue.


Please find some more codes of 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, and MISC on the below page:

Top 100+ C Programming codes – KLE Technological University



Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!