By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Output to Printer

P: n/a
Hi,

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

/Johann
Nov 14 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Isaac writes:
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.
Nov 14 '05 #2

P: n/a
"Isaac" <i.*****@btinternet.com> writes:
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
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #3

P: n/a
"Isaac" <i.*****@btinternet.com> wrote in message

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.

Nov 14 '05 #4

P: n/a
Martin Dickopp wrote:
"Isaac" <i.*****@btinternet.com> writes:

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.


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.
Nov 14 '05 #5

P: n/a
Martin Ambuhl <ma*****@earthlink.net> writes:
Martin Dickopp wrote:
"Isaac" <i.*****@btinternet.com> writes:
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.


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.
</off-topic>
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.


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
--
,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
/ ,- ) http://www.zero-based.org/ ((_/)o o(\_))
\ `-' `-'(. .)`-'
`-. Debian, a variant of the GNU operating system. \_/
Nov 14 '05 #6

P: n/a
On Sat, 8 May 2004 23:00:19 +0100, "Malcolm"
<ma*****@55bank.freeserve.co.uk> wrote in comp.lang.c:
"Isaac" <i.*****@btinternet.com> wrote in message

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.


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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #7

P: n/a
Isaac wrote:
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.

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.