twitter
    Find out what I'm doing, Follow Me :)

How Do We Print?

Load the last example file in this chapter, the one named printdat.c for an example of how to print. This program should not present any surprises to you so we will move very quickly through it.

#include "/sys/stdio.h"
main( )
{
FILE *funny,*printer;
int c;
funny = fopen("TENLINES.TXT","r"); /* open input file */
printer = fopen("PRN","w"); /* open printer file */
do {
c = getc(funny); /* got one character from the file */
if (c != EOF) {
putchar(c); /* display it on the monitor */
putc(c,printer); /* print the character */
}
} while (c != EOF); /* repeat until EOF (end of file) */
fclose(funny);
fclose(printer);
}



Once again, we open TENLINES.TXT for reading and we open PRN for writing. Printing is identical to writing data to a disk file except that we use a standard name for the filename. There are no definite standards as far as the name or names to be used for the printer, but the 1616/OS names are, "CENT:", "SA:", and "SB:". Check your documentation for your particular implementation
.
Some of the newest MS-DOS compilers use a predefined file pointer such as "stdprn" for the print file. Once again, check your documentation. The program is simply a loop in which a character is read, and if it is not the EOF, it is displayed and printed. When the EOF is found, the input file and the printer output files are both closed. You can now erase TENLINES.TXT from your disk. We will not be using it in any of the later
chapters