Solved

Console App Printing using Borland C++ Builder 4.5

Posted on 2002-03-10
10
467 Views
Last Modified: 2011-10-03
Hi,

I need to write to the printer froma Console App.

Previously when I used Turbo C++ the follwing worked

fprintf(stdprn,.....   etc

It doesnt in C++ Builder 4.5

How can I get round this. Any info would be useful..
0
Comment
Question by:tinybear
  • 7
  • 3
10 Comments
 

Author Comment

by:tinybear
ID: 6854360
BTW Im running C++ Builder on Win XP it that is relevant, but I would need it to work in Turbo C++ if possible as that is the compiler used by my college ( they have limited resources)
0
 

Expert Comment

by:wenderson
ID: 6854761
In a Windows program, you don't have theprinter file already open, so you can do the following:

FILE *stdprn = fopen("LPT1", "wt");
fprintf(stdprn, "Printing Test\n\n");

Wenderson

0
 

Author Comment

by:tinybear
ID: 6855513
Cheers will give it a go when I get back home.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:tinybear
ID: 6855537
Hi,

Cant get it to work in Turbo C++

will try it in C++ Builder later

0
 

Expert Comment

by:wenderson
ID: 6855796
Why not? What's happening?
I tested it here and it works just fine.
Be aware that some printers just start printing when you send a full page or a eject page sinal.

Wenderson
0
 

Author Comment

by:tinybear
ID: 6855897
I'll get a full list of the errors when I get in to college later but..

The FILE keyword generates errors


0
 

Author Comment

by:tinybear
ID: 6856133
In Turbo C++ 3.0

When I compile with the FILE *stdprn = fopen("LPT1","wt")

The first error generated is

Cannot Convert 'FILE *' to 'FILE * &[4]'

and then several others.

0
 

Accepted Solution

by:
wenderson earned 50 total points
ID: 6858349
What version of Turbo C++ 3.0 are using, DOS or Windows?
The DOS version already has stdprn defined as a global variable, just include stdio.h.
There's no need to open the file, because it's already opened, just do:

#include <stdio.h>
int main()
{
  fprintf(stdprn, "Teste\n");
  return 0;
}

I don't remember if the Windows version has a stdprn defined, if not, you must do "FILE *stdprn = fopen("LPT1", "wt");" before you start printing.

Wenderson
0
 

Author Comment

by:tinybear
ID: 6859738
Yes it is the DOS version (the college really need to update), but I use Borland C+ Builder3 at home, so I need the program to work in both..which is my dilemma.

Maybe I'll just have to compile 2 versions.
0
 

Author Comment

by:tinybear
ID: 6863750
Please Allocate Points to wenderson
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question