Loading

c program to copy a text file

C Program to Copy a Text File


#include<stdio.h>
#include<conio.h>

void main()
{
  FILE *fp1,*fp2;
  char file1[500],file2[500];
  char x;
  printf("\nENTER THE SOURCE FILE:");
  gets(file1);
  fp1=fopen(file1,"rb");
  printf("\nENTER THE DESTINATION FILE:");
  gets(file2);
  fp2=fopen(file2,"wb");
  if(fp1!=NULL && fp2!=NULL)
  {
    while((x=getc(fp1))!=EOF)
    putc(x,fp2);

  }

  else
    printf("\nERROR CREATING FILE...");

  fclose(fp1);
  fclose(fp2);
  getch();
 }

This entry was posted in , , , . Bookmark the permalink.

Leave a reply