/* Pro129B.C */
/*  How to use different folder(directory) location files?             */
/*  Please use sprinft() which works as a buffer.                      */
/*  In the sample below, infile.txt locates in C:\ToRead\  folder.     */
/*  While, outfile.txt requires a folder "Result" at the same place    */
/*  of the program.  Outfile.txt will be written into \Result\ folder.  */   

#include<stdio.h>
#include<string.h>
char inline [100]; 

int main(void)
{
     char readFN[20], writeFN[20];                  /* For reading and writing filenames */
     FILE *infp, *outfp;

     sprintf(readFN,  "C:\\ToRead\\infile.txt");    /* Specify reading filename location absolutely     */
     sprintf(writeFN, "Result\\outfile.txt");       /* Specify writing-out filename location relatively */

     if( (infp=fopen(readFN, "r"))!=NULL )          /* Only existing file is opened for reading */
     {
          outfp=fopen(writeFN, "w");                /* Start write-out file. */

          while(fgets(inline, 100, infp)!=NULL){              
               printf(inline);                      /* For screen monitor */
               fprintf(outfp, "%s", inline);        /* Echo writing down into outfile.txt */
	  }
     }
     fclose(infp);
     fclose(outfp);
     return 0;
}