COPY DATA FROM ONE FILE TO ANOTHER FILE USING C PROGRAM









#include<stdio.h>
int main(){
  FILE *p,*q;
  char file1[20],file2[20];
  char ch;
  printf("\nEnter 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);
 return 0;
}




Alogrithm:
**






2.  Write a c program to delete a file.
3. Write a c program to copy a file from one location to other location.
6. Write a c program which writes string in the file.

7 comments:

Anonymous said...

i like these programs,please can you post more programs it will be helpful

Unknown said...

you forget the stdlib header file :)

Anonymous said...

thank u

Anonymous said...

good

Anonymous said...

i dnt even undrstand a simple program. but i want learn it. plz help me dudes

Anonymous said...

need algorithm

Unknown said...

you forget the stdlib header file :)