C program to copy the contents of one file into another

C program to copy the contents of one file into another

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

void main()
{
FILE *fp1,*fp2;
char ch,*f1,*f2;
clrscr();

printf(“Enter source file name(ex:source.txt): “);
scanf(“%s”,f1);
printf(“Enter destination file name(ex:destination.txt): “);
scanf(“%s”,f2);

fp1=fopen(f1,”r”);
fp2=fopen(f2,”w”);

if(fp1==NULL||fp2==NULL)
{
printf(“File could not open!!”);
exit(0);
}

while((ch=getc(fp1))!=EOF)
putc(ch,fp2);

fclose(fp1);
fclose(fp2);
}

3 thoughts on “C program to copy the contents of one file into another”

  1. hello there ,,,,

    can you help me to create a blog
    or teach me how to create a blog ?
    please

    i want to create a drawing blog

  2. in if condition there should be only if(f1==NULL) because file 2 can be either pre-written or it can be NULL also.it is user depended.Thanks for the Source,useful though.

Leave a Comment

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