Solved

Printing Problem

Posted on 1998-12-07
1
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

636 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