home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_10 / 8n10088b < prev    next >
Text File  |  1990-07-22  |  1KB  |  42 lines

  1.  
  2. ******
  3. Listing 5
  4.  
  5. /* Write to printer, file, or nowhere */
  6.  
  7. #include <stdio.h>
  8. #define GO_TO_PRINTER 1
  9. #define GO_TO_DISK_FILE 2
  10.  
  11. #define PRINTER_DEVICE "PRN"   
  12. #define NULL_DEVICE "NUL"
  13.        /* Keep these here for ease of change to other systems */
  14.  
  15. print_function(where_to_go, filename)
  16. /* Prints on printer or a file */
  17. int where_to_go;       /* Where to print */
  18. char *filename;        /* Name of file (if not printer) */
  19.           {è          FILE *file_printer; /* pointer to a file */
  20.           int x, y, z;
  21.  
  22.           x = 5;
  23.           y = y;
  24.           z = x + y;
  25.  
  26.           /* open the device */
  27.           if (where_to_go == GO_TO_PRINTER)
  28.                file_printer = fopen (PRINTER_DEVICE, "w");
  29.            else if (where_to_go == GO_TO_DISK_FILE)
  30.                file_printer = fopen(filename, "w");
  31.           else
  32.                /* Dump to a Nul file */
  33.                file_printer = fopen(NULL_DEVICE,"w");           
  34.  
  35.           /* print the line */ 
  36.           fprintf (file_printer, "The answer is %10d", z);
  37.  
  38.           /* close the printer */
  39.           fclose (file_printer);
  40.           }
  41.  
  42.