Solved

Printing Problem

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 and use switch statements in the C programming language.

776 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