C Program to COPY DATA FROM ONE FILE TO ANOTHER File

  1. #include<stdio.h>  
  2. int main(){  
  3.   FILE *p,*q;  
  4.   char file1[20],file2[20];  
  5.   char ch;  
  6.   printf("\nEnter the source file name to be copied:");  
  7.   gets(file1);  
  8.   p=fopen(file1,"r");  
  9.   if(p==NULL){  
  10.       printf("cannot open %s",file1);  
  11.       exit(0);  
  12.   }  
  13.   printf("\nEnter the destination file name:");  
  14.   gets(file2);  
  15.   q=fopen(file2,"w");  
  16.   if(q==NULL){  
  17.       printf("cannot open %s",file2);  
  18.       exit(0);  
  19.   }  
  20.   while((ch=getc(p))!=EOF)  
  21.       putc(ch,q);  
  22.   printf("\nCOMPLETED");  
  23.   fclose(p);  
  24.   fclose(q);  
  25.  return 0;  

Comments

Popular posts from this blog

How to configure Glowroot with Liferay

How to Get Back Asus Zenphone 5 from Soft Brick

How to Unlock Boot Loader of Htc Explorer