How to print directly from compile screen?

This is a discussion on How to print directly from compile screen? within the C Programming forums, part of the General Programming Boards category; I need to have a program print what it outputs after it is done compiling, and I have no idea ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    65

    How to print directly from compile screen?

    I need to have a program print what it outputs after it is done compiling, and I have no idea how I'm going to get it to do that. For example, if my program was something basic like:

    Code:
    #include<stdio.h>
    
    int main()
    {
        printf("Hello world!");
        getchar();
    }
    It would output " Hello world! " in the black box. How do I get it to send that to my printer by adding to the same program?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by mcotter222 View Post
    It would output " Hello world! " in the black box. How do I get it to send that to my printer by adding to the same program?
    Printing is very platform specific. On Windows, you MIGHT be able to run your program like this:

    Code:
    myprog.exe > lpt1:
    If that doesn't work, you'll have to use the actual Windows print APIs, which I am not familiar with.

    On UNIX systems, you pipe your output to lpr:

    Code:
    myprog | lpr
    Or, if you want the program to do it internally, you'll have to open a pipe to lpr, then reset stdout to point to this pipe. All this is rather complicated, so you need to specify what platform you're working with.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    I work with a windows xp. I don't know what UNIX is, but it keeps coming up in my google searches. Is that something I put on my computer or something entirely different? also, I want the print to be directly in the c code if possible. I edited the code to look like this:
    Code:
    #include<stdio.h>
    
    int main()
    {
        printf("Hello world!");
        getchar();
        myprog.exe > lpt1;
    }
    but it wouldn't compile.

    Thanks
    -Matt

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Is that something I put on my computer or something entirely different?
    you firstly shoud compile your original code
    then start it using the command line above

    One way - Start/Run...
    cmd

    cd "Folder where the exe is located"
    <program name>.exe > lpt1

    Second way:
    in VS - Project/Settings/Debugging

    Command - add at the end of string >lpt1
    save and press Ctrl+F5

    Third way... create shortcut
    etc
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    65
    So how I can't have it directly in the code? I don't understand option 2, and how would the last one make it print?
    -Matt

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If it's a console appliction (in Windows), you can open "lpt:" as a file [for writing]:
    Code:
      FILE *flpt;
      flpt = fopen("lpt:", "w");
      if (flpt == NULL) { 
         perror("open LPT:"); 
         exit(1); 
      }
    ...
    Then use "flpt" as your destination file.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by mcotter222 View Post
    I work with a windows xp. I don't know what UNIX is, but it keeps coming up in my google searches. Is that something I put on my computer or something entirely different?
    UNIX is a family of operating systems which have been around since before Windows existed. Linux is one example. You can install it on your computer, but it's an entire operating system, not a program.

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    3
    using video memory could be a way (0x13)

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by jhandu View Post
    using video memory could be a way (0x13)
    Huh? What does 0x13 stand for, and how does this relate to printing the output of the program to the printer?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    0x13 stands for mode 13h -- you know, the 320x200 256-colour VGA DOS screen mode.

    Not a good thing to recommend here.
    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.

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by dwks View Post
    0x13 stands for mode 13h -- you know, the 320x200 256-colour VGA DOS screen mode.
    That's what came to mind for me too, but I have no clue how it even remotely relates...

  12. #12
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by jhandu View Post
    using video memory could be a way (0x13)
    ... to do output to a printer? Now, I don't know much about hardware programming, but I'm pretty sure that's not going to work.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I think maybe the OP was thinking that the printer must have some video memory somewhere that you can write to, sort of how direct video access works with mode 13h.

    It doesn't, by the way. At least not that I've ever heard of, and definitely not portably, and probably not on any modern printers.
    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.

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And of course, compared to opening lpt: as I suggested, drawing text in "video memory" is not too much more complicated

    Just design your own fonts, write your text rendering functions, and off you go. Not that printers actually have video memory, but anyways.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by dwks View Post
    I think maybe the OP was thinking that the printer must have some video memory somewhere that you can write to, sort of how direct video access works with mode 13h.

    It doesn't, by the way. At least not that I've ever heard of, and definitely not portably, and probably not on any modern printers.
    I am trying to imagine what the driver for a memory-mapped peripheral device would look like, and it doesn't look pretty. The printer almost certainly has a frame buffer, but you're not going to access that through a parallel or USB port!

Page 1 of 5 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How does this user get screen to run under root?
    By Overworked_PhD in forum Tech Board
    Replies: 2
    Last Post: 06-28-2009, 09:31 AM
  2. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  4. how to print a file on the screen
    By tameeyore in forum C Programming
    Replies: 4
    Last Post: 09-18-2005, 12:00 PM
  5. Print Screen
    By /\/\ E /\/ @ in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-11-2002, 05:37 PM

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