home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20537 < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.7 KB  |  65 lines

  1. Path: sparky!uunet!gatech!rutgers!igor.rutgers.edu!remus.rutgers.edu!ficara
  2. From: ficara@remus.rutgers.edu (ken ficara)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: fprintf to ImageWriter??? Help!
  5. Summary: Trying to write to printer w/ stdio functions
  6. Keywords: debugging macintosh imagewriter think c
  7. Message-ID: <Jan.2.12.45.21.1993.16716@remus.rutgers.edu>
  8. Date: 2 Jan 93 17:45:22 GMT
  9. Organization: Rutgers Univ., New Brunswick, N.J.
  10. Lines: 53
  11.  
  12. In Scott Knaster's HOW TO WRITE MACINTOSH SOFTWARE, 2nd ed, page 118,
  13. a useful debugging technique is suggested: opening the printer port
  14. and using standard printing functions to send debugging info straight
  15. to the printer.
  16.  
  17. He suggests the following in Pascal:
  18.  
  19. var
  20.     printer: Text;
  21. begin
  22.     Reset (printer, '.bout');
  23.     WriteLn (printer, 'Text text text...');
  24.  
  25. I tried to translate this to C and came up with the following:
  26.  
  27. #include <stdio.h>
  28.  
  29. main ()
  30. {
  31.     int        i;
  32.     FILE    *printerPort;
  33.     
  34.     if (!(printerPort = fopen ( ".bout", "w")))
  35.         printf ("%s","Cannot open printer.");    
  36.     else
  37.         printf ("Opened printer.");
  38.     if    (ferror(printerPort))
  39.         printf ("%s","Error on printer port stream.");    
  40.         
  41. /*
  42.     for (i=1 ; i<=10 ; i++)                        
  43.         printf (printerPort, "%s", "this is a test\n\r");
  44. */
  45.  
  46.     fclose (printerPort);    
  47.  
  48. }
  49.  
  50.  
  51. This program reports that the printer port has been opened and does
  52. not report an error on the stream. But it crashes with an address
  53. error,even if the printf statement is commented out.
  54.  
  55. The Pascal version doesn't work either, but I'm not as familiar with Pascal.
  56.  
  57. Does anyone know how to do this? It would be an incredibly useful
  58. technique but for the crashing. :)
  59.  
  60. Thanks!
  61.  
  62.  
  63. Ken Ficara                                        ficara@remus.rutgers.edu
  64. GEnie: K.FICARA / Compuserve: 71311,1461 / AOL: KENFICARA / Prodigy: (Ha!)
  65.