Thread: Output to printer

  1. #1
    Registered User
    Join Date
    Aug 2002

    REVISED: "Output to a Printer"

    This program listing from the book "C By Example" (QUE pub. 1993) page 538, "Writing to a Printer" does not work for me.

    I'm using WIN98 and Borland TURBO C++ 3.1 and
    Borland C++4.0. The program is compiled as print.c using the IDE
    option. The Printer is an HP DeskJet 832C.

    The code suggested by 'moi' will not compile while using Borland Turbo C++ 3.1, but does compile when using Borland C++ 4.0.
    But the output would not go to the printer.....

    The suggestion from Salem confuses me (I'm new to programming).
    Do not know the correct format to use at the Command line (is this the DOS C prompt?). Or should the "print file.txt" be included in the C program?

    Program listing from the book:

    /*Writing to a printer */

    #include <stdio.h>
    FILE *prnt;

    prnt = fopen("LPT1", "w");
    fprintf(prnt, "This is a test.\n");


    The output always goes to the screen, not to the printer.
    No problem printing the code.

    Thanks in advance for any suggestions.
    Last edited by noraa; 08-03-2002 at 10:48 AM.

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    sitting in front of me right now is a wasted piece of paper with "this is a test." written on it. my code isnt exactly the same as yours, but the only difference is a little error checking and platform-specfic stuff. what OS are you under? dos box in win95? also newer printers dont expect raw unformatted data from the parallel port i dont think; i have an epson stylus color original, and i know when it came out the raw text output from lpt to printer was a dying thing (it has the economy/condensed, font, load eject buttons on it, nessecary for this sort of thing).

    #include <stdio.h> 
    int main(void) 
      FILE *prnt;
      prnt = fopen("/dev/lpt1", "w"); 
      if (prnt)
        fprintf(prnt, "This is a test.\n"); 
        printf ("error opening printer\n");
      return 0;
    hello, internet!

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    DOS (and the windows console) has a print command built in - and strangely enough, it's called print

    D:\code>print /?
    Prints a text file.

    PRINT [/D:device] [[drive:][path]filename[...]]

    /D:device Specifies a print device.

    Now use this to print a text file of your choice.

    Does it work?

    If it doesn't, then you've got bigger problems than your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic C input output program help
    By trevordunstan in forum C Programming
    Replies: 2
    Last Post: 01-27-2008, 06:41 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  3. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM