[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Printing from C/C++ ?





Erik Karlin wrote:

On Mon, Nov 28, 2005 at 01:55:48PM -0500, H.S. wrote:
John Carline wrote:
Hi All,

Can someone give me a good reference for printing from a C program or
perhaps a few lines of C or C++ code that will route program formated
data/text to my local printer.

There seems to be a glaring lack of this information in the 5 C/C++
books I have.

Thanks for any assistance.
John

you can print through emacs, the whole file or parts of it and much more.

Let us say you want to print a part of a C++ file in emacs where syntac
highlighting is ON. Select the desired region with your mouse, then
Ctrl-u M-x ps-print-region-with-highlighting is the command I think.
This will print the region to a PS file and you can then send that file
a printer. Alternatively, you can send the output directly to printer
instead of a PS file.

->HS

I believe what he's looking for is how to print from within a C/C++ app.
My question is why re-invent the wheel. Why recode lp, just do one of:
	system("lp /tmp/my_report")
	fork/exec("lp /tmp/my_report")
	p = popen("lp"); fprintf(p, ...)

They would all seem to work while keeping up the traditions of unix


Since I really didn't want to write, print and then delete a file, popen()/pclose() looks like exactly what I want.

It's surprising that they're not mentioned in any of the books I have - which includes O'Reilly's C++ in a nutshell and Tom Swan's GNU C++ for Linux. I guess it was too basic.

They forgot about someone like like me who writes one "C" application every five years or so, and has to "learn again" what I once knew :)

Now that you've pointed me in the right direction, it looks like the man pages will have all I need.

Thanks
John

--
Powered by the Penguin



Reply to: