Thread: Printing to the printer

  1. #1
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68

    Printing to the printer

    I have found many code examples on the Net, like the one below, but cannot get any one of them to work. (I guess LPT1 is outdated.) Plese help.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
     
    int main ( void )
    {
         FILE * Printer = fopen("LPT1", "w");
         FILE * FilePointer;
         char str[256];
         char buf[BUFSIZ];
         printf("File name?\n");
         scanf("%s", str);
         FilePointer = fopen(str, "r");
         if( !FilePointer )
         {
            printf("File does not exist\n");
            return -1;
         }
         while( fgets ( buf, sizeof buf, FilePointer ) != NULL ) 
         {
                fprintf(Printer, "%s", buf);
         }
             printf("\nPrinting..\n");
         fprintf(Printer, "\f");
             return 0;
    }

  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
    How about starting with you telling us what your OS and Compiler is.

    Do you perhaps end up with a file called LPT1 ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by Salem View Post
    How about starting with you telling us what your OS and Compiler is. ?
    My Os is Windows 10. My compiler is MinGW64.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Do you have a real printer on a real port labelled LPT1?

    Do you have a real printer on a USB port?

    Do you have a network printer, accessed either wirelessly or wired, on your LAN?

    Can I use USB for LPT1? - Microsoft Community
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    [QUOTE=Salem;1295280]Do you have a real printer on a real port labelled LPT1?

    Do you have a real printer on a USB port?

    Do you have a network printer, accessed either wirelessly or wired, on your LAN?

    /QUOTE]


    I have a printer connected wirelessy. I could wire it up but that would be much less convinient.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Wired/Wireless doesn't make a bean of difference.

    What matters is that it is on the LAN.

    LPT1 to a Network Printer?? - Spiceworks
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by Salem View Post
    Wired/Wireless doesn't make a bean of difference.

    What matters is that it is on the LAN.
    Yes the connection between the using PC and the used printer is wirelessy via WIFI (i.e., exchane via the modem).

  8. #8
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by Paderi View Post
    Yes the connection between the using PC and the used printer is wirelessy via WIFI (i.e., exchane via the modem).
    You have identified the cause of the difficulty, i.e. connecting to a network printer. Hopefully you are able to tell me how to effectively do it.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Inside an cmd.exe window enter.
    Code:
    mode
    It is possible; but, unlikely that the network printer created an LPTn entry.

    The mode command should show all LPTn not currently being used.
    At least it does that for COMn ports.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by stahta01 View Post
    Inside an cmd.exe window enter.
    Code:
    mode
    It is possible; but, unlikely that the network printer created an LPTn entry.

    Tim S.
    Is there a possible solution via a system call? If so, might you know what the code ahould be? I can activate Notepad from within the program, but printing via that route would be a dirty solution.

  11. #11
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by Paderi View Post
    Is there a possible solution via a system call? If so, might you know what the code ahould be? I can activate Notepad from within the program, but printing via that route would be a dirty solution.
    If I code system("print") the response is: no file to print. So there must be some way to print via a system call. What is that way?

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    So, did you run the mode command?
    Was an LPTn listed?

    Did you try mapping your network printer to an LPTn?

    Are you a help vampire who is unable to use Google?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  13. #13
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by stahta01 View Post
    So, did you run the mode command?
    Was an LPTn listed?

    Did you try mapping your network printer to an LPTn?

    Are you a help vampire who is unable to use Google?

    Tim S.
    I have been spending nany mours on the Internet looking for the answers. Why on earth have such a negative attitued towards a peron asking a question? I have never done mapping.

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Because you are acting like an help vampire, idiot, or an troll!

    You refuse to answer questions!

    You seem incapable of using Google to answer your questions.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  15. #15
    Registered User Paderi's Avatar
    Join Date
    Apr 2020
    Posts
    68
    Quote Originally Posted by stahta01 View Post
    . . . you are acting like an help vampire, idiot, or an troll! <snipped>bTim S.
    I couldn't do what you asked me to do. I had a quesion that I asked in a clear way. No need to throw the contents of your garbage at me because of that and wave your ego flag.
    Last edited by Paderi; 04-23-2020 at 08:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing with printer
    By g4j31a5 in forum C++ Programming
    Replies: 5
    Last Post: 09-14-2006, 01:06 PM
  2. Printing the program to a printer
    By zombie in forum C++ Programming
    Replies: 2
    Last Post: 01-31-2005, 05:31 PM
  3. Printing Debug Without Printer :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-15-2002, 02:18 PM
  4. Printing to a printer....I already did a search :)
    By fastmonkey in forum C++ Programming
    Replies: 1
    Last Post: 10-09-2002, 01:51 AM
  5. printing on network printer
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2001, 02:10 PM

Tags for this Thread