954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C programming....Sending data from Console to connected USB printer

I am doing a personal project to get to know C a little better:
Some essential information

> I have a usb printer
> I am using Windows 7 OS..suggest better Os..haha..not NT or ms-dos ;)
> I am using Visual C++ 2008 Express edition..coding strictly in C however(You can suggest other compilers that would be better to solve the problem)

I want to make a program that while running, has the capabilities to send data to the printer to be printed on paper. I already know that I can write to file and than open notepad and print the code.. I don't want to do that however. Is there a way to send the data to the printer via USB..if only serial is available, I'll take it..but preferably USB


I know others have posted this but their threads are left empty due to no response by themselves...
Any suggestion will be accepted

I've tried
int main()
{
FILE *fp = fopen( "LPT", "w");
if ( fp == NULL ) {
perror( "Unable to open printer" );
}
else
{
fprintf( fp, "Hello World\n\f" );
fclose( fp );
}
getch();
return 0;
}

And nothing...I've changed LPT to PRN, LPT:, LPT1, LPT1:, LPT2(and it's derivatives), file paths..nothing works..They only create files with no file extensions that contain Hello world..

CoilFyzx
Newbie Poster
8 posts since Apr 2011
Reputation Points: 10
Solved Threads: 1
 

Sending data to a laser printer is very complicated. You could use win32 api printer functions, such as EnumPrinters() and OpenPrinter().

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Is it the same for an inkjet? And are you saying that I can't use plain C as it is to do this?

CoilFyzx
Newbie Poster
8 posts since Apr 2011
Reputation Points: 10
Solved Threads: 1
 

To print a file you would need to interact with device drivers of the printer ... I dont know if that is easily achievable by using standard c programing

abhimanipal
Master Poster
742 posts since Dec 2009
Reputation Points: 114
Solved Threads: 104
 

>>Is it the same for an inkjet?

An injet is in the class of a laser printer.

The easiest way to send files to the printer is with this free PrintFile utility .

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

How would I use it C though, because I'm designing a program. Please help

CoilFyzx
Newbie Poster
8 posts since Apr 2011
Reputation Points: 10
Solved Threads: 1
 

Get that utility program then call it from your C program.

Or if you want to do it all from within your C program, read this Microsoft document and example programs.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: