Printing in C - Turbo C - DOS

ninja_turtle_2003 used Ask the Experts™
I am trying to get a C Program to print to my printer.
However, I don't want to use fprintf(stdprn,"message").
I am trying to write directly to the printer, using outportb.
I can initialise the printer, and bring it into (what I assume is a) data receival state, with paper drawn in.
However, I cannot actually get the printer to print the data I send to it; it will only linefeed afterwards, and throw the paper out.
The code I have is this:

#include <stdio.h>
#define DATA 0x378
#define CONTROL DATA+2

void main()
        outportb(CONTROL, 0xC); /*Reset*/
        outportb(CONTROL, 0x7); /*Draw Paper*/
        outportb(CONTROL, 0xA0); /*Data Ready Mode*/
        outportb(DATA, "THIS IS A TEST MESSAGE"); /*My message*/
        outportb(DATA, '\n'); /*Line return*/
        outportb(DATA, '\f'); /*Linefeed*/
        outportb(CONTROL, 0xFF); /*Clear and eject paper, also RESET*/

This resets the printer, draws paper in, and puts the printer in DATA mode.
However, it doesn't print THIS IS A TEST MESSAGE.
All it does is print the line return, and linefeed.
It then resets the printer, and throws the paper out.

How can I get it to print the message as well?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The problem relies in the improper use of outportb().
This function writes a BYTE at the specified port. When you try to send your message, you have to split it into characters before. You could use a function like this:

void print_message(char *message)
{int i;
   for (i=0;i<strlen(message);i++)

void main()
       print_message("This is my test message");
Of course, don't forget to include <string.h>

Hope this helps

Best regards,
Top Expert 2005

BTW  Your terminology in your comments is a bit off:

\r is carriage return (line return in your terms)
\n is line feed
\f is form feed (eject page)

You could embed these into the text of the string you
are printing.
it good
but i want in unix environment
plese send this information to my email :
only in c


No, I still can't get it to work.
I have tried doing this:

void pmsg(char msg[30])
        int a;
                outportb(0x378, toascii(msg[a]));
        outportb(0x378, '\r');

I have tried making '\r' into '\f' '\n' and even '\vt'
None of these seem to do anything.

Is there some command to make the printer print the data in buffer?
Printer is a Canon BJC4000.
PAQed, with points refunded (30)

E-E Admin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial