PRINT a text to printer

mircea

Beta member
Messages
1
hello dear programmer!

problem: Print a text to printer
prg.language: C
request: any workable solution is welcome

I've already tryde this:...but doesn't work
/*--------------------------------*/
#include <stdio.h>

int main(void) {
FILE* prn;
prn=fopen("/dev/usb/-lp0", "w");
/* -lp0=file attached to printer in Linux O.S. */
if(fopen==NULL) {
puts("Cannot reach the printer!\n");
exit(1);
}
fprintf(prn, "This text should be printed.\n");
return 0;
}

Thanks in advance,
mircea
 
outdated!!! pfff! Grrr, OK, perhaps a litle, but still damn usefull!

#include < iostream.h >
#include < fstream.h >
int main(void)
{
int i=1234;
char name[15];
float fval=123.456;
ofstream printer; // ofstream means out file stream
printer.open("lpt1");
cout<<"Enter a word (Max 14 chars): ";
cin.getline(name,14, '\n');
printer << "The values are: " << i <<" " << fval <<" "<
return 0;
}

Thats an example of how to use lpt1,
I'm not too sure about USB printers, I don't think you can just write to the device in the same way you could LPT1, there might be some kind of driver you have to interact with.
 
Back
Top Bottom