Thread: printing command.

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    printing command.

    can anybody tell me the command to print out a variable straight to the printer please.
    p.s (not 'print screen' or 'screen dumps')

    thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Which OS/Compiler?
    What type of printer, and what sort of port is it plugged into?
    What type of program - console or GUI ?

  3. #3
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    Quote Originally Posted by dac
    can anybody tell me the command to print out a variable straight to the printer please.
    p.s (not 'print screen' or 'screen dumps')

    thanks.
    I came across this
    http://support.microsoft.com/default...kb;en-us;23976

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    im using dev-C++, this is for my AS level coursework project! 'village hall'. have XP at home but NT at school, so needs to work on both.
    using the DOS box.
    i just need a command which can print my variable text to a printer (reciept).

  5. #5
    Master of Puppets rwmarsh's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    96
    I am trying to do the same thing. I have tried those tips and nothing happens. These are the codes that I have tried
    Code:
    #include <stdio.h>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        FILE *stream;
    
        stream = fopen("LPT1", "w");
        fprintf(stream, "a line of text\n");
        fclose(stream);
        cin.get();
        return 0;
    }

    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
    {
        ofstream printer("lpt1");
        printer << "a line of text\f" << flush;
        cin.get();
        return 0;
    }
    none of these work for me. no errors just nothing prints. I know the printer is working right because I tested it.

    Using DEV-C++ under Windows XP
    With an HP Deskjet Printer on lpt1

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    none of these work for me. no errors just nothing prints. I know the printer is working right because I tested it.
    Does this work?
    Code:
    C:\>echo Hello, World! > lpt1
    If so, you can just redirect the output of your program from the command line:
    Code:
    C:\>program > lpt1
    BTW, some compilers define a stream called stdprn.
    Code:
    fprintf(stdprn, "a line of text\n");
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM
  5. Printing Command
    By Daniel Deprose in forum C Programming
    Replies: 4
    Last Post: 09-28-2002, 09:27 AM