Friday, March 30, 2018

Write A Program Using File Handling To Copy The Contents Of One File To Another file.

/* Copy the content of one file to another file */

 

#include< stdio.h>

#include< stdlib.h>

#include< conio.h>

 int main()

 {

 FILE *fptr1;

 FILE *fptr2;

 char ch;

     // Open one file for reading

fptr1 = fopen("Quote.c", "w");

 

fputs("Knowledge helps you to reach destination provided you know what your       destination is ",fptr1);

 fclose(fptr1);

 

 /*Open another file for writing */

 fptr1 = fopen("Quote.c","w");

 fptr2=fopen("new.c","r");

 while(!feof(fptr1))

 {

  ch=getc(fptr1);

  putc(ch,fptr2);

  }

  while(ch!=EOF);

  fclose(fptr1);

  fclose(fptr2);

 getch();

 }

 

Output:-

Copy File

No comments:

Post a Comment

Life Articles And News:

Life Articles And News: