Answer to Question #304324 in C for omsri

Question #304324

Develop a C program to copy the content of one file and store that content in another file.



Runtime Input :


Good Morning


Output :


Good Morning

1
Expert's answer
2022-03-01T08:04:00-0500
#include <stdio.h>

int main()
{

    char* filename = "D://finput.txt";
    char* filename2 = "D://foutput.txt";
    char str[256];
    FILE *mfile;
    FILE *mfile2;
   
    if((mfile = fopen(filename, "r"))==NULL)
    {
        perror("Error occured while opening file");
        return 1;
    }
    if((mfile2 = fopen(filename2, "w"))==NULL)
    {
        perror("Error occured while opening file");
        return 1;
    }
    while((fgets(str, 256, mfile))!=NULL)
    {
        fputs(str, mfile2);
    }

    fclose(mfile);
    fclose(mfile2);
    printf("\nFile %s copied to %s\n", filename, filename2);

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS