Listing 5

/* Write to printer, file, or nowhere */

#include <stdio.h>
#define GO_TO_PRINTER 1
#define GO_TO_DISK_FILE 2

#define PRINTER_DEVICE "PRN"
#define NULL_DEVICE "NUL"
      /* Keep these here for ease of change to other systems */

print_function(where_to_go, filename)
/* Prints on printer or a file */
int where_to_go;       /* Where to print */
char *filename;        /* Name of file (if not printer) */
         {
         FILE *file_printer; /* pointer to a file */
         int x, y, z;

         x = 5;
         y = y;
         z = x + y;

         /* open the device */
         if (where_to_go == GO_TO_PRINTER)
             file_printer = fopen (PRINTER_DEVICE, "w");
          else if (where_to_go == GO_TO_DISK_FILE)
             file_printer = fopen(filename, "w");
         else
             /* Dump to a Nul file */
             file_printer = fopen(NULL_DEVICE,"w");

         /* print the line */
         fprintf (file_printer, "The answer is %10d", z);

         /* close the printer */
         fclose (file_printer);
         }