Hello...
I am trying to modify a program from a text book and I have a puzzeling question.
The text tries to output information from a file to the printer using the stdprn, however, on Linux, this is undefined, so I decided to define it.
However, I am finding that I have to define it in 2 locations in the program for it to work proporly. Is there a way I can define it in one location and not throughout the code?
Here is the code and it does compile and work. I am defining prn for referance:
As I stated, this does compile and work as it is, but just seems silly to me to have it defined in 2 locations. I tried to put it first above the void and then in the main {}, but its not working that way.Code:#include <stdlib.h> #include <stdio.h> void do_heading(char *filename); int line = 0, page = 0; int main( int argv, char *argc[] ) { char buffer[256]; FILE *prn; /* First definition */ prn = popen("/usr/bin/lpr", "w"); /* First definition */ FILE *fp; if( argv < 2 ) { fprintf(stderr, "\nProper Usage is: "); fprintf(stderr, "\n\nprint_it filename.ext\n" ); return(1); } if (( fp = fopen( argc[1], "r" )) == NULL ) { fprintf(stderr, "Error opening file, %s!\n\n",argc[1]); return(1); } page = 0; line = 1; do_heading( argc[1]); while( fgets( buffer, 256, fp ) != NULL ) { if (line % 55 == 0) do_heading( argc[1] ); fprintf( prn, "%4d:\t%s", line++, buffer ); } fprintf( prn, "\f" ); fclose(fp); return 0; } void do_heading( char *filename ) { FILE *prn; /* Second Definition */ prn = popen("/usr/bin/lpr", "w"); /* Second Definition */ page++; if (page > 1) fprintf( prn, "\f" ); fprintf( prn, "Page: %d, %s\n\n", page, filename); }
Any ideas on how to get this to work?
Thanks!!!
Joe



LinkBack URL
About LinkBacks




