Write a 'C' Program to copy the contents of one file into another file using command line arguments.
#includevoid main(int argc, char *argv[]) { FILE *fs,*ft; char ch; if(argc != 3) { printf("\nINVALID NUMBER OF ARGUMANTS."); getch(); exit(0); } fs = fopen(argv[1],"r"); if(fs == NULL) { printf("SOURCE FILE DOES NOT EXIST."); getch(); exit(0); } printf("CONTENTS OF SOURCE FILE::>\n"); while(1) { ch = fgetc(fs); if(ch == EOF) break; printf("%c",ch); } fclose(fs); ft = fopen(argv[2],"w"); fs = fopen(argv[1],"r"); if(ft == NULL) { printf("CAN NOT OPEN TARGET FILE"); getch(); exit(0); } while(1) { ch = fgetc(fs); if(ch == EOF) break; fputc(ch,ft); } fclose(fs); fclose(ft); printf("\nCONTENTS OF TARGET FILE::>\n"); ft = fopen(argv[2],"r"); while(1) { ch = fgetc(ft); if(ch == EOF) break; printf("%c",ch); } fclose(ft); getch(); }
Write a 'C' Program to copy the contents of one file into another file using command line arguments.
Reviewed by
on
April 24, 2015
Rating: