• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Printing Problem

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
tester090797
Asked:
tester090797
1 Solution
 
emmonsCommented:
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now