home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_01 / 1n01038b < prev    next >
Text File  |  1990-05-17  |  1KB  |  48 lines

  1. /*
  2. **  Figure 2
  3. **
  4. **  Multiple printer support with default to a single printer
  5. **  connected to the PRN device.
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. #define NUM_OF_PRNTRS 6
  11.  
  12. FILE *printer[NUM_OF_PRNTRS] = {stdprn};
  13.  
  14. /*
  15. **  assign_printer()
  16. **
  17. **  Call with printer number and device name
  18. **
  19. **     printer number should be in the range of 0 to NUM_OF_PRNTRS-1
  20. **     device should be "LPT1", "LPT2", "LPT3", "COM1", COM2", or a log file
  21. **
  22. **  Returns 0 if successful, -1 if error
  23. **
  24. **  Then do all printer output with fprintf(), fputs(), fputc(), etc.
  25. **  using printer[printer_number] as the output stream
  26. */
  27.  
  28. int cdecl assign_printer(int number, char *device)
  29. {
  30.         FILE *fp;
  31.  
  32.         if (NUM_OF_PRNTRS <= number || NULL == (fp = fopen(device, "w")))
  33.                 return -1;
  34.         printer[number] = fp;
  35.         return 0;
  36. }
  37.  
  38. #ifdef DEBUG                                    /* Test code follows    */
  39.  
  40. main()
  41. {                                       /* Leave printer[0] = stdprn    */
  42.         assign_printer(1, "CON");       /* Set printer[1] to the screen */
  43.         assign_printer(2, "p.log");     /* Set printer[2] to log file   */
  44.         fputs("This is a printer test\n", printer[0]);
  45.         fputs("This is a screen test\n", printer[1]);
  46.         fputs("This is a log test\n", printer[2]);
  47. }
  48.