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..

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

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

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

>>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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.