                             /* Chapter 10 - Program 7 - ANYFILE.C */
#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp1, *fp2, *imprime;
char oneword[100], filename[25], exitfilename[25], resp;
char *c;

   printf("Enter filename -> ");
   scanf("%s", filename);            /* read the desired filename  */
   fp1 = fopen(filename, "r");
   if (fp1 == NULL)
   {
      printf("File failed to open\n");
      exit (EXIT_FAILURE);
   }





typedef struct tagOFNA {
   DWORD        lStructSize;
   HWND         hwndOwner;
   HINSTANCE    hInstance;
   LPCSTR       lpstrFilter;
   LPSTR        lpstrCustomFilter;
   DWORD        nMaxCustFilter;
   DWORD        nFilterIndex;
   LPSTR        lpstrFile;
   DWORD        nMaxFile;
   LPSTR        lpstrFileTitle;
   DWORD        nMaxFileTitle;
   LPCSTR       lpstrInitialDir;
   LPCSTR       lpstrTitle;
   DWORD        Flags;
   WORD         nFileOffset;
   WORD         nFileExtension;
   LPCSTR       lpstrDefExt;
   LPARAM       lCustData;
   LPOFNHOOKPROC lpfnHook;
   LPCSTR       lpTemplateName;
#





   printf("Exit filename -> ");
   scanf("%s", exitfilename);
   fp2=fopen(exitfilename, "w");

   printf("\nDo you want to print this file? (y/n)");
   scanf("%s", resp);
   if (resp=='y')
     {
       imprime=fopen("PRN", "w");
       if (imprime==NULL)
         {
           printf("Printer not available...\n");
           exit(EXIT_FAILURE);
         }
     }
   do 
   {
      c = fgets(oneword, 100, fp1);  /* get one line from the file */
      if (c != NULL)                
       {
         printf("%s", oneword);      /* display it on the monitor  */
         fprintf(fp2, c);
         if (resp=='y') putc(c, imprime);
        }
   } while (c != NULL);              /* repeat until NULL          */

   fclose(fp1);
   fclose(fp2);

   return EXIT_SUCCESS;
}

