Output to Printer

I

Isaac

Hi,

I have been trying to find out, in C programming language, how to send
output to a printer. Can anyone help?

/Johann
 
O

osmium

Isaac said:
I have been trying to find out, in C programming language, how to send
output to a printer. Can anyone help?

There are at least a couple of ways. One is to create a text file and
subsequently print that file. Another is to use the API provided by the OS.
If you chose that method, post your question to a group that discusses your
OS.
 
M

Martin Dickopp

Isaac said:
I have been trying to find out, in C programming language, how to send
output to a printer. Can anyone help?

Cannot be done in *standard* C, which is the topic of this newsgroup.
There is not even a guarantee that the device running a C program can
access a printer at all (think microwave oven).

Please ask in a newsgroup dedicated to your OS. For example, if you're
programming for Unix, comp.unix.programmer would be appropriate.

Martin
 
M

Malcolm

Isaac said:
I have been trying to find out, in C programming language, how to > send
output to a printer. Can anyone help?The portable solution is to se printf() to send output to stdout, and then
redirect it to the printer using the OS.

A lot of older implementations provide stdprn (standard printer) which
despite its name isn't standard.
Modern printing isn't done on a character basis, but describes the page
using some sort of graphical format. This means that interfaces tend to be
rather complicated, and off-topic here because platform-specific.
What you can do is write a postscript-format file, which is ASCII so
writable by a portable program. However unless your printing is quite simple
you'd probably need to use a library to generate the file.
 
M

Martin Ambuhl

Martin said:
Cannot be done in *standard* C, which is the topic of this newsgroup.

Sure, it can. If the printer is accessible as something with which a
FILE * can be associated, fopen(), fprintf(), and fclose() work just
fine. This case obtains in Windows (and DOS), Unix, and most other systems.
There is not even a guarantee that the device running a C program can
access a printer at all (think microwave oven).

The point is right, but the question rather presumes a machine with a
usable printer, innit?
Please ask in a newsgroup dedicated to your OS. For example, if you're
programming for Unix, comp.unix.programmer would be appropriate.

Your advise is usually very good, but I think you overreached this time
in the "please post elsewhere" response.
 
M

Martin Dickopp

Martin Ambuhl said:
Sure, it can. If the printer is accessible as something with which a
FILE * can be associated, fopen(), fprintf(), and fclose() work just
fine. This case obtains in Windows (and DOS), Unix, and most other
systems.

Okay, but there's no standard way to do it. IMHO, this is no different
from accessing networks, serial ports, arbitrary locations on the
screen, or "raw" keyboard input, all of which are also possible in
standard C if the device is accessible through an associated FILE *
object.

<off-topic>
On Unix at least, accessing a locally attached printer through something
which can be fopen'ed often requires special privileges, but there's a
different way to print which is also available to programs which run
without without special privileges. So using fopen to print on Unix
might at least not be the best advice for that platform.
Your advise is usually very good, but I think you overreached this time
in the "please post elsewhere" response.

I still don't think so, but given the other replies to the OP, I concede
(with apologies to the OP) that I'm probably wrong.

Martin
 
J

Jack Klein

output to a printer. Can anyone help?
The portable solution is to se printf() to send output to stdout, and then
redirect it to the printer using the OS.

A lot of older implementations provide stdprn (standard printer) which
despite its name isn't standard.

What do you mean by "a lot of older implementations"? There were
certainly a lot of older implementations, usually for each and every
platform other than MS-DOS, that did not. Why is some
platform-specific, non-standard extension worth mentioning at all? It
is certainly off-topic.
 
J

Joe Wright

Isaac said:
Hi,

I have been trying to find out, in C programming language, how to send
output to a printer. Can anyone help?

/Johann
Back in the Old Days when Bell Labs belonged to the phone company,
there was precisely one line printer in the building and it didn't
belong to Dennis. Hell, Dennis couldn't even get a video terminal.
Budgets you know. Dennis had to settle for the ubiquitous ASR-33
teletype machine. The phone company made them and for Bell Labs,
they were cheap. So stdin was the 33's keyboard and stdout was its
printer. Really!

C's print controls map precisely to ASR-33 functionality. We have
BS, CR, LF, FF because the teletype would do that.

But seriously now, printing is not the business of a programming
language. It is the business of the OS and hardware subsystem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top