Solved

Printing Problem

Posted on 1998-12-07
1
183 Views
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>

main()
{
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.
0
Comment
Question by:tester090797
1 Comment
 
LVL 4

Accepted Solution

by:
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>

main()
{
      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);
      }
}

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

705 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

22 Experts available now in Live!

Get 1:1 Help Now