Can any one spot why this listing Will not compile?

/*print_it.c-This program preints a listing with line numbers */
#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 *fp;
 if( argv < 2 )
 {
  fprintf(stderr, "\nProper Usage is: ");
  fprintf(stderr, "\nprint_it filename.ext\n" );
  return(1);
 }
 if (( fp = fopen(argc[1], "r" )) == NULL )
 {
  fprintf( stderr, "Error opening file %s!", 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(stdprn, "%4:\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 );
}
    return 0;
}

using dev-C++ editor compiler/linker .

Dick

Recommended Answers

All 5 Replies

what are the error(s) your compiler gives you ? A quick once-over looks like braces are missing from lines 26 and 38, and remove the semicolon on line 38.

Can any one spot why this listing Will not compile?

/*print_it.c-This program preints a listing with line numbers */

#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 *fp;

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

 if (( fp = fopen(argc[1], "r" )) == NULL )
 {
  fprintf( stderr, "Error opening file %s!", 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(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 );

    return 0;
}

Now it will compile but it won't work because the compiler you are
using doesn't have stdprn define.
It is not that easy to send data to a printer any more.
Change stdprn for stdout and you'll see the input being directed to
the screen.

The errors are "stdprn" undefined for every line it appears on.
one would think that if a listing were in a book and you using the compiler that came with the book that any listing would work except for type O's.

dick

The errors are "stdprn" undefined for every line it appears on.
one would think that if a listing were in a book and you using the compiler that came with the book that any listing would work except for type O's.

dick

Read the NOTE that is right below that code in the book were you took that code from.

Thank you Aia now I have to check the DEV-C++ to find thier way to do the printer.
at least you've givin me a way to find a solution I'm thinking.
Thank you again it is most appreciated.

Dick

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.