source for printing file or generated output...

I am working on a SCO box,  with C.   What I am doing is writing a labels program for a client and would like to know the best of going about sending info to the printer of choice.  I had asked a question like this earlier, but instead of a file, I would like to send output to the printer.  For example,  if my program got data like this:

John Smith
1234 General Drive
Some City, Some State, 12345

how would I go about sending that to printer??  I could open the dev file myself, but that could cause problems.  The way I had thought about doing was to generate a temp file then print the file, but I don't think that is a good way of doing it.  Thanks guys.
Who is Participating?
mliberiConnect With a Mentor Commented:
The best way to do the job is using the 'popen' function

FILE *w = popen("lp -dmyprt","w");

if (!w) { /* manage error condition */ }
fprintf(w,"%s\n%s\n%s\n%s\n%s\n\f","John Smith","1234 General Drive","Some City, Some State,","12345");
To print in POSIX OS u can redir a output stream to device directy, for example:
cat myfile > /dev/device_name
print "John Smith\n1234 General Drive\nSome City, Some State,\n12345\n\f" > /dev/device_name
if u need print in C
FILE *fp;
fprintf(fp,"%s\n%s\n%s\n%s\n%s\n\f","John Smith","1234 General Drive","Some City, Some State,","12345");

bye bye xcuse my english

kellyjjAuthor Commented:
thanks for your help, however, writing directly to the printer port would cause problems with the spooler.  Basically what I want is to send output to the spooler and let The OS handle it.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

u can try redirect or write to spooler like a device, the difference is in /dev/spool/nameofspool
If your program is "myprog" and your printer "myprt"
then enter :
myprog | lp -dmyprt
kellyjjAuthor Commented:
thanks,  that is what I figured out.  Nice to see that I was going down the right road.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.