[C / C ] Copy file in C
The code below will copy the contents of the file you enter into 1 Other files so you can name. If no source file is offline. Note that the file can be the same or different folder.
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp1,*fp2;
char ch,f1[1000],f2[1000];
printf("Enter source file name(ex:source.txt): ");
scanf("%s",f1);
fp1=fopen(f1,"r");
if(fp1==NULL)
{
printf("File could not open!!");
return 0;
}
printf("Enter destination file name(ex:destination.txt): ");
scanf("%s",f2);
fp2=fopen(f2,"w");
while((ch=getc(fp1))!=EOF)
putc(ch,fp2);
printf("%s is created and copied", f2);
fclose(fp1);
fclose(fp2);
return 0;
}




Recent Comments