#include int FileCopy(char [], FILE *); int main() { char Fsource[15],destination[15]; FILE *psource; int check=0; printf("\n\nPlease Enter the source filename to be copied with its extension\n (max 15 characters):\n\n"); scanf("%s",&Fsource); psource=fopen(Fsource,"rb"); if(psource==NULL){ printf("Error opening file\n\n"); main(); } printf("Please enter the destination filename, including extension:\n\n"); scanf("%s",&destination); check = FileCopy(destination,psource); if(check==0){ printf("Error copying file\n\n"); main(); } if(check==1){ printf("File copy complete\n\n"); } system("pause"); return 0; } int FileCopy(char newfile[], FILE *sourcefile){ char buffer[1024],*buffer2; long long fsize,buf2size = 0; FILE *destination; destination=fopen(newfile,"wb"); fseek(sourcefile,0,SEEK_END); fsize = ftell(sourcefile); rewind(sourcefile); for(;fsize!=0;){ if(ftell(sourcefile)>(fsize-(1024))){ buf2size = ((fsize-(ftell(sourcefile)))); buffer2 = (char *) malloc(buf2size * sizeof(char)); if(buffer2==NULL){ printf("Buffer Memory Allocation Error\n\n"); return 0; } fread(buffer2, 1, buf2size, sourcefile); fwrite(buffer2, 1,buf2size, destination); fclose(sourcefile); fclose(destination); return 1; } fread(buffer, 1, 1024, sourcefile); fwrite(buffer, 1, 1024, destination); } return 0; }