What Is Needed to Send C Program Output Directly to a Printer
-                         C - directing output to printerHi, 
 I'm reading a book virtually C and am stuck on a section regarding how to send text directly to the printer (as opposed to the screen).I have: When I compile and run the programme using gcc, my printer low-cal flashes, but aught else happens.Lawmaking: #include <stdio.h> principal() { FILE *printer = fopen("/dev/usb/lp0", "w"); fprintf(printer, "How-do-you-do World."); fclose(printer); return 0; }When I add the line: and so my printer prints out a bare page.Lawmaking: fprintf(printer, "\f"); What am I doing wrong? 
 Am grateful for any assistance, only please conduct in mind I am a beginner in C.
 
-                         Re: C - directing output to printerYou may need to fflush() the output. What results do you get with: Code: #include <stdio.h> primary() { FILE *printer = fopen("/dev/usb/lp0", "w"); fprintf(printer, "Howdy World.\due north\f"); fflush(printer); fclose(printer); return 0; }
 
-                         Re: C - directing output to printerHi, 
 Cheers for the reply.
 I compiled and ran the lawmaking you suggested and unfortunately the printer but spat out a blank page.
 This seems to be caused by the "\f" character.
 I likewise just tried printing something from the text editor to make sure that information technology is not the printer at fault and this worked fine  
 Any ideas?
 
-                         Re: C - directing output to printerI looked into an application I wrote over 11 years ago under Solaris, and I must've had the same problem yous are experiencing. In the lawmaking, I placed a annotate that sending information to the printer does non work as "gracefully" as ane would hope. My cheesy solution was to output the data to a file, and then using the system() library call, I was able to phone call "lp". Sorry I cannot assistance more. 
 
-                         Re: C - directing output to printerI would imagine virtually "modern" printers do not wait simply straight Ascii text, and that the drivers generate something altogether more complex. I don't think you tin can send a text file for instance direct to "/dev/usb/lp0" - you need to go via the printer commuter - i.eastward. lp. using lp sounds like a skillful idea to me - equally you would then the states the preferences that the user has set - instead of your application over-riding them. 
 
-                         Re: C - directing output to printerThanks for your answer.. 
 I accept been playing around with this and googling all evening and am unfortunately still no closer to solving my problem.
 What is irritating me is that I am obviously able to connect to the printer in some style equally it will chuck out a blank page when I send it:
 If anyone else has any ideas and so I'd be grateful.Code: fprintf(printer, "\f"); 
 Thank you in accelerate.
 
-                         Re: C - directing output to printerThat seems like it makes sense. I found various means to send output to the printer in C, ranging from 'stdprn', to 'PRN' to 'LPT1:' to '/dev/lp1' Originally Posted by                      Tony Flury Originally Posted by                      Tony Flury  
 Everything I tin can find online withal, points to this beingness rather dated.
 Could yous give me a hint as to what the command would wait like to send output via the printer driver?
 I tried this, without success:
 Code: FILE *printer = fopen("lp0", "west");
 
-                         Re: C - directing output to printerI would employ the idea of dumping your output to a text file then using the lp command to print it. 
 
-                         Re: C - directing output to printerThis kind of thing is fine for merely messing around, but a serious awarding that wants to impress should never even recall of talking to the printer directly similar this. Instead you should employ a printing API that abstracts away the actual printer device. The simply fourth dimension I've printed from an application, I used wxWidgets which handled it all rather only. 
 
-                         Re: C - directing output to printerThe "\f" is a form feed, it ejects the folio and gets another. Try this: Notation "-P PDF" sets the printer. In my case I have installed "cups-pdf" to test information technology by printing to a pdf file (I have no printer here anyway).Lawmaking: #include <stdio.h> int main(int argc, char **argv) { FILE *printer = popen("/usr/bin/lpr -P PDF", "west"); if (printer == Nil) render 1; printf("OK\northward"); fprintf(printer, "alsdjakljdlaskjd\northward"); pclose(printer); return 0; }You can meet the list of printers with the "lpinfo" command. 
 
howittworidence64.blogspot.com
Source: https://ubuntuforums.org/showthread.php?t=1301744