Copying content of one file to another file - C

Q. Write a program to copy content of one file into another file.
 #BIT-C Programming-2019-GroupB-9No-4 Marks-Solution
#AssignmentNo12
==> Code goes like this:
#include <stdio.h>
main()
{
    FILE *fptrSource, *fptrDest;
    char ch;
    fptrSource = fopen("D:\\original.txt", "r");
    if(fptrSource==NULL)
    {
        printf("\n FIle can not be opened");
        exit(1);
    }
    fptrDest = fopen("D:\\newfile.txt", "w");
    if(fptrDest==NULL)
    {
        printf("\n File can not be created");
        exit(1);
    }
    while((ch = getc(fptrSource)) != EOF)
        putc(ch, fptrDest);
    printf("\n Successfully copied!!!");
    fclose(fptrSource);
    fclose(fptrDest);
    return 0;
}

Output:






Note : You have to create original.txt in D: first with some content inside it.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you


Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment