Apperently there is an undeclared identfiier "stdprn". Please help

/* PRINT_IT.C-This program prints a listing with line numbers! */

#include <stdio.h>

void do_heading(char *filename);

int line, page;

main( int argv, char *argc[] )
{
    char buffer[256];
    FILE *fp;

    if( argv < 2 )
    {
        fprintf(stderr, "\nProper Usage is : ");
        fprintf(stderr, "\n\nPRINT_IT filename.ext\n" );
        exit(1);
    }

    if (( fp = fopen( argc[1], "r")) == NULL )
    {
        fprintf( stderr, "Error opening file, %s!", argc[1]);
        exit(1);
    }

    page = 0;
    line = 1;
    do_heading( argc[1]);

    while( fgets( buffer, 256, fp ) != NULL )
    {
        if( line % 55 == 0 )
            do_heading( argc[1] );

        fprintf( stdprn, "%4d:\t%s", line++, buffer );
    }

    fprintf( stdprn, "\f" );
    fclose(fp);
    return 0;
}

void do_heading( char *filename )
{
    page++;

    if ( page > 1)
        fprintf( stdprn, "\f" );

    fprintf( stdprn, "Page: %d, %s\n\n", page, filename );
}

stdprn was a non-standard identifier provided by some very old DOS compilers. If you're not using a very old DOS system with something like Borland C from 1985, it won't work.

As moschops said. Also, in modern compilers you would use either stdout, or stderr. One other thing. It is good practice to initialize external variables such as page and line where they are declared. IE:

int line = 1;
int page = 0;

Uninitialized variables tend to cause many sleepless nights! The way you are using them is ok since you initialize them in main() before they are used, but this is "best practices" I am talking about, and how to minimize bugs in your code, especially after other people get their hands on it! :-)

Also, modern compilers require that you declare that main() will return an int explicitly. IE: int main( int argc, char *argv[] ). Do note that I changed the argument names. The term int argc refers to the argument count (number of entries in argv[]) and argv[] the vector (array) of arguments. Your usage will likely cause a downgrade by your instructor since it is very non-standard.

Here's a thread on the same topic. You can open a printer port by opening "lpt1:", but that assumes the printer is attached to the LPT1 port on the computer. Most modern computers today don't have such a port, printers are attached either by USB or wifi. In that case you have to go through the printer driver, which can get complicated.

The easiest way to print simple text is to just save it to a file then call system() to send it to the printer, letting the operating system handle all the complicated stuff.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.