Printing Problem

Posted on 1998-12-07
Last Modified: 2010-07-27
I'm trying to output the following to the printer, but most C books are vague about this. This code to output is not working.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int p = 0;
char buf[1024];
FILE *f;
// FILE *prtfile;
// char FName[80] = "LPT1";
//prtfile = fopen(FName, "w");
f = open("test.c", "r");
while (fgets(buf, sizeof(buf), f)){
//fprintf(prtfile,"%d %s", ++p, buf);
Anything better than this to output a file("test.c") to the printer.
Question by:tester090797
1 Comment

Accepted Solution

emmons earned 100 total points
ID: 1254930
Better than this?  This seems to work fine for me.
What is it that you are looking for?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

      int p = 0;
      char buf[1024];
      FILE *f, *prtfile;
      char *FName = "LPT1:";
      prtfile = fopen(FName, "wa+");
      f = fopen( "test.c", "r");
      while ( fgets( buf, sizeof( buf), f)){
            fprintf( prtfile,"%d %s", ++p, buf);


Featured Post

Free camera licenses with purchase of My Cloud NAS

Milestone Arcus software is compatible with thousands of industry-leading cameras for added flexibility. Upon installation on your My Cloud NAS, you will receive two (2) camera licenses already enabled in the software. And for a limited time, get additional camera licenses FREE.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now