INF: Sending Output to a Printer

ID Number: Q23976

3.00 4.00 5.00 5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

There are three possible ways to send output to a printer. They are

as follows:

1. The most convenient way to send output to the printer is to write

to the preopened stream "stdprn" with the fprintf() function. The

following example will output a line of text to the printer:

#include <stdio.h>

main()

{

fprintf(stdprn, "a line of text\n");

}

2. Output also can be sent to the printer by doing the following:

a. Open the device PRN, LPT1, or LPT2 as a file with the fopen()

function.

b. Use fprintf() to write to the handle returned by fopen().

This approach is similar to Method 1, but requires some

additional set-up overhead, as follows:

#include <stdio.h>

main()

{

FILE *stream;

stream=fopen("PRN", "w");

fprintf(stream, "a line of text\n");

}

3. In MS-DOS it also is possible to send output to the printer from

a C program by using the BIOS printer services under INT 17h, as

follows:

service 0: send byte to the printer.

service 1: initialize the printer.

service 2: get printer status.

These BIOS interrupts can be executed by using the library functions

int86() or int86x(), which are described in the "Microsoft C Compiler

Run-Time Library Reference."

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax 7.00