#includevoid main() { FILE *fs,*ft; char s_file[80],t_file[80],ch; clrscr(); printf("ENTER THE SOURCE FILE NAME:: > \n"); gets(s_file); fs = fopen(s_file,"r"); if(fs == NULL) { printf("SOURCE FILE DOES NOT EXIST."); getch(); exit(); } printf("\nCONTENTS OF SOURCE FILE::>\n"); while(1) { ch = fgetc(fs); if(ch == EOF) break; printf("%c",ch); } fclose(fs); printf("\nENTER TARGET FILE NAME ::>\n"); gets(t_file); ft = fopen(t_file,"w"); if(ft == NULL) { printf("CAN NOT OPEN TARGET FILE"); getch(); exit(); } fs = fopen(s_file,"r"); while(1) { ch = fgetc(fs); if(ch == EOF) break; fputc(ch,ft); } fclose(fs); fclose(ft); ft = fopen(t_file,"r"); printf("\nCONTENTS OF TARGET FILE::>\n"); while(1) { ch = fgetc(ft); if(ch == EOF) break; printf("%c",ch); } printf("\nFILE COPIED SUCCESSFULLY....."); getch(); } /*OUTPUT:: ENTER THE SOURCE FILE NAME:: > a.txt CONTENTS OF SOURCE FILE::> Hello.... Good Morning........ This is ABC ENTER TARGET FILE NAME ::> b.txt CONTENTS OF TARGET FILE::> Hello.... Good Morning........ This is ABC FILE COPIED SUCCESSFULLY..... */
Write a 'C' Program to copy the contents of one file into another file.
Reviewed by
on
April 24, 2015
Rating: