Welcome to the World of Programming

Welcome to the World of Programming

Search this blog

Copy One File to another File

/**********************************************************************
 * Program to open a file to read information from it
 * and write that information into another file
 * ********************************************************************/

#include "stdio.h"

int main(){
FILE *f1=NULL,*f2=NULL;
char a;
f1=fopen("fileread","r");
if(f1==NULL){
printf("Cannot open File to read");
exit(1);
}
f2=fopen("filewrite","w");
if(f2==NULL){
printf("Cannot open file to write");
exit(1);
}
while(!feof(f1)){
a=getc(f1);
putc(a,f2);
}
fclose(f2);
fclose(f1);
return 0;
}

1 comment:

  1. feof() Checks whether the End-of-File indicator associated with stream is set, returning a value different from zero if it is.
    it's same as MACRO EOF(==-1) in C.

    ReplyDelete