Copy the content of one file to another in c

#include <stdio.h>
#include <conio.h>

int main(void)
{
    FILE *p1//source file pointer
    FILE *p2//target file pointer
    char ch[100];

    //opening to write content on source file(optional)
    p1 = fopen("text.txt""w+");
    printf("Enter the text to store in file : ");
    gets(ch);
    fputs(chp1);
    fclose(p1);

    //-------------------------------------------------------------
    // copying the content of source file to target file
    p2 = fopen("target.txt""w+");
    p1 = fopen("text.txt""r+");
    while (!feof(p1))
    {
        fgets(ch100p1);
        fputs(chp2);
    }
    fclose(p1);
    fclose(p2);

    //------------------------------------------------------------

        //opening to view content on target file(optional)
    p2 = fopen("target.txt""r");
    printf("content of copied file is : ");
    while (!feof(p2))
    {
        fgets(ch100p2);
    }
    printf("%s"ch);
    fclose(p2);
}
SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

1 comments: