Tuesday, February 10, 2015

Copy File Contents

/* Write a program in C to copy the data from one file to another */ #include <stdio.h> int main() { FILE *p, *q; char file1[20], file2[20]; char ch; printf("Enter the source file name to be copied: "); gets(file1); p = fopen(file1, "r"); if(p==NULL) { printf("Cannot open %s", file1); exit(0); } printf("\nEnter the destination file name: "); gets(file2); q=fopen(file2, "w"); if(q == NULL) { printf("Cannot open %s", file2); exit(0); } while((ch=getc(p))!= EOF) putc(ch, q); printf("\nCOMPLETED"); fclose(p); fclose(q); getch(); return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar