Success - Output to Printer

This is a discussion on Success - Output to Printer within the C Programming forums, part of the General Programming Boards category; After much experimenting (I am a novice), I found a way to send the results of a FileName.exe to a ...

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

    Wink Success - Output to Printer

    After much experimenting (I am a novice), I found a way to send the results of a FileName.exe to a printer.

    I'm using Borland C++ 4.0 and WIN98. I tried to duplicate the
    printer routine using Borland Turbo C++ 3.1 with no success.

    The test program:

    /* Print2 printer test */
    #include <stdio.h>
    FILE *prnt;

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

    fclose(prnt);
    return(0);

    }


    I selected the Target Type as "Application.exe". And the Platform as "DOS Standard".

    I compiled using Project/Make all. When I tried Project/Compile,
    the printer would not actvate.

    I saved the program and closed all windows. At the MS DOS
    prompt, I typed; C:\bc4\bin\FileName.exe and hit Enter.

    The Printer activated and produced the desired output.
    One problem. Something in the code is causing the printer to take a long time to spit out a copy. But I can manually speed up the output by pressing the paper feed button. The printer functions normally during other operations.

    Anybody have a suggestion for a code modification that would speed up the printer???

    Thanks for prior help and for any additional help...

  2. #2
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    you are not telling the printer to spit out the finished product. if it spits it out at all without your intervention, then it's simply because it timed out waiting for more data. however i do not know the exact commands to eject a sheet, maybe a bunch of \n would do it
    hello, internet!

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

    Wink Works in Windows too...

    I just discovered that after I compiled the test printer program and clicked on RUN, the printer activated in <Windows>. I did not
    have to go to the <MS DOS> prompt.....

    So, it appears that my original selection of the Target Type as EasyWin.EXE and Platform Type as Windows 3.x(16)
    prevented ANY Printer activity.

    Application.exe for the Target Type and DOS Standard for the Platform Window is the correct selection to activate the Printer with a C program (with Borland C++ 4.0) in Windows.

    The Printer is still slow.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    You seem to be having a touch of trouble manipulating your programming enviroment.

    Expierment with this program:
    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;
    }
    The world is waiting. I must leave you now.

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    For dos, try adding the linefeed and formfeed. I had a similar problem, but it was with masm not C. Adding the linefeed and formfeed solved the "not ready" problem.

    Code:
    fputs("string\xA\xC", filep);
    /* or your method of choice for file I/O */
    Last edited by ronin; 08-03-2002 at 10:03 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

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

    Wink Correcting the Printer delay

    After much experimenting to fix the very long Printer delay, I
    included: fprintf(prnt, "\f"); before the fclose(prnt); statement.

    The Printer output now occurs without delay.....

    All Smiles now!!


    /* "PRINTER OUTPUT TEST" */

    #include <stdio.h>

    FILE *prnt;

    main()

    {

    prnt = fopen("lpt1", "w");

    fprintf(prnt, "\nThis is TEST#1\n");
    fprintf(prnt, "This is TEST#2\n");
    fprintf(prnt, "This is TEST#3\n");
    fprintf(prnt, "This is TEST#4\n");

    fprintf(prnt, "\f"); /* Prevents Printer hangup */

    fclose(prnt);

    return (0);

    }

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, 05:41 PM
  2. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 09: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, 10: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, 10:29 AM

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