C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-03-2002, 08:23 PM   #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...
noraa is offline   Reply With Quote
Old 08-03-2002, 08:28 PM   #2
moi
Registered User
 
moi's Avatar
 
Join Date: Jul 2002
Posts: 945
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!
moi is offline   Reply With Quote
Old 08-03-2002, 09:04 PM   #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.
noraa is offline   Reply With Quote
Old 08-03-2002, 09:08 PM   #4
Unleashed
 
Join Date: Sep 2001
Posts: 1,755
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.
Shadow is offline   Reply With Quote
Old 08-03-2002, 09:14 PM   #5
Casual Visitor
 
Join Date: Oct 2001
Posts: 313
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 */
__________________
I'm not a programmer....
I'm not a computer science major....
This is only a hobby....

Last edited by ronin; 08-03-2002 at 10:03 PM.
ronin is offline   Reply With Quote
Old 08-04-2002, 09:12 AM   #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);

}
noraa is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic C input output program help trevordunstan C Programming 2 01-27-2008 06:41 PM
2d game JordanCason Game Programming 5 12-08-2007 10:08 PM
Having trouble making a function do what I want. Shamino C++ Programming 9 12-07-2007 11:20 AM
Trying to store system(command) Output punxworm C++ Programming 5 04-20-2005 06:46 PM
sorting output on student info program indigo0086 C++ Programming 2 11-05-2002 11:29 AM


All times are GMT -6. The time now is 09:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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