Thread: newbie question dealing with an error

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    newbie question dealing with an error

    I may have posted something along these lines before, but I cannot seem to find the answer to my question in any of my previous posts. I have a program from a teach yourself C book, and am having an error. The program is supposed to print a program listing with line numbers and I got it to work at one point but can't seem to do it now.

    here is the code

    Code:
    /* print_it.c--This program prints a listing with line numbers! */
    
    #include <stdlib.h>
    #include <stdio.h>
    
    void do_heading(char *filename);
    
    stdprn = open(USB001, O_WRONLY);
    
    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, "\n\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 );
    }
    Whenever I try to compile it using gcc, I get this error:

    printit.c:8: error: expected identifier or '(' before '&' token

    As I am just starting out with C, I would greatly appreciate any help with this. Thanks a bunch.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The open command is not a standard C function, I don't think; and that appears to be line 8. There is a _open defined in MS somewhere, maybe that's what you meant?

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    5

    ok new question.

    I'm in Linux now and I get it to compile with the code listed below. The problem is that instead of printing the heading on the page it belongs to, it prints it on a separate piece of paper (i.e. for a 1 page program, it prints the code on one page and then the heading on another page)

    Here is the code:

    Code:
    /* print_it.c--This program prints a listing with line numbers! */
    
    #include <stdlib.h>
    #include <stdio.h>
    
    void do_heading(char *filename);
    
    stdprn = open("/usr/bin/lpr", "w");
    
    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, "\n\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 );
    }
    Again, I am very new at this (Day 1 basically). So any suggestions would be very welcome. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM