File Copy Program in C Language #include #include #include void main(int arg,char *arr[]) { FILE *fs,*ft; char ch; clrscr(); if(arg!=3) { printf("Argument Missing ! Press key to exit."); getch(); exit(0); } fs = fopen(arr[1],"r"); if(fs==NULL) { printf("Cannot open source file ! Press key to exit."); getch(); exit(0); } ft = fopen(arr[2],"w"); if(ft==NULL) { printf("Cannot copy file ! Press key to exit."); fclose(fs); getch(); exit(0); } while(1) { ch = getc(fs); if(ch==EOF) { break; } else putc(ch,ft); } printf("File copied succesfully!"); fclose(fs); fclose(ft); }
Open arg1-file in read mode. Open arg3-file in append mode(create if not exist). copy arg1-file to arg3-file. close arg1-file. Open arg2-file in read mode. copy arg2-file to arg3-file. close arg2-file. close arg3-file. Done arg1-file and arg2-file merges and copied in arg3-file.