Go Back   Computer Forums > General Computing > Programming
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 11-29-2003, 02:33 PM   #1
Beta Member
Join Date: Nov 2003
Posts: 1
Question PRINT a text to printer

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");
fprintf(prn, "This text should be printed.\n");
return 0;

Thanks in advance,

mircea is offline   Reply With Quote
Old 11-04-2004, 07:01 AM   #2
Baseband Member
sean82007's Avatar
Join Date: May 2004
Posts: 87
Default Re: PRINT a text to printer

sorry dont know C but i no that C is kinda outdated.

They say if you play a Microsoft Windows CD backwards it says Satanistic messages; but if you play it the other way it still installs windows.

- 2.4 ghz
- 120gb
- 768 KBPS DSL Connection
- 9200 128mb PCI Adapter
sean82007 is offline   Reply With Quote
Old 11-04-2004, 07:34 AM   #3
Site Team
root's Avatar
Join Date: Mar 2004
Posts: 7,872
Default Re: PRINT a text to printer

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
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.
root is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 10:08 AM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0