Output to printer

This is a discussion on Output to printer within the C Programming forums, part of the General Programming Boards category; This program listing from the book "C By Example" (QUE pub. 1993) page 538, "Writing to a Printer" does not ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    6

    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;

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

    fclose(prnt);
    return(0);
    }

    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 11:48 AM.

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    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).

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

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    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, 07: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21