Get Update on recent Technology & Programming

Tuesday, 14 November 2017

C Program to Copy a file to another file

Posted by   on Pinterest

C Program to Copy a file to another file





#include<stdio.h>

#include<stdlib.h>

int main(void)

{

 FILE *sptr, *dptr;

 char ch;

 if((sptr=fopen("source.txt","r"))==NULL)

 {

  printf("Error in opening source file\n");

  exit(1);

 }

 if((dptr=fopen("destination.txt","w"))==NULL)

 {

  printf("Error in opening destination file\n");

  exit(1);

 }

 while((ch=fgetc(sptr))!=EOF)

  fputc(ch,dptr);

 fclose(sptr);

 fclose(dptr);

 return 0;

}




No comments:
Write comments

Hey, we've just launched a new custom color Blogger template. You'll like it -
Join Our Newsletter