Found 'if' expecting ')'

This is a discussion on Found 'if' expecting ')' within the C Programming forums, part of the General Programming Boards category; Can somebody help me to debug this. And if you can explain me why is this happening? Thanks Code: /* ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    Unhappy Found 'if' expecting ')'

    Can somebody help me to debug this. And if you can explain me why is this happening? Thanks


    Code:
    /* PRINT_IT.C-This program prints a listing with line numbers! */
     #include <ansi_c.h>
     #include <stdio.h>
    
     void do_heading ( char *filename);
    
     int line, page;
    
     main ( int argv, char *argc[] )
     {
         char buffer[256];
         FILE *fp;
    
         if( argv < 2 )
         {
               printf( "\nProper Usage is: " );
               printf(   "\n\nPRINT_IT filename.ext\n" );
               exit (1);
         }
    
         if(( fp = fopen ( argc[1], "r"  )) ==NULL)
         {
               printf (   "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] );
    
               printf ( "%4d:\t%s", line++, buffer);
         }
    
         printf (   "\f");
         fclose (fp);
         return 0;
     }
    
     void do_heading ( char *filename )
     {
         page++;
    
         if (page > 1)
    code tags added by Hammer
    Last edited by seby24; 11-18-2002 at 05:36 AM.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    while ( fgets( buffer, 256, fp ) != NULL)

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    yes, monster is right. remember, when using parenthesis (sp?) you must always have a mental "mirror" of them (as well as '{' and '}') and there should be an even number of them in the line/code.

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Found 'if' expecting ')'
    Not that hard to understand, imo.
    Remember that the compiler often reports the error one line below the actual error.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Sang-drax
    Not that hard to understand, imo.
    Remember that the compiler often reports the error one line below the actual error.
    because it actually reports the error when it sees the next thing, and its not what it was looking for (the parenthesis in this case)
    hello, internet!

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    5

    Lightbulb

    Originally posted by Monster
    while ( fgets( buffer, 256, fp ) != NULL)

    Thanks a lot! I think this is more often happening when people copy source codes from somewhere than when they write it themselves (as I did).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 11:17 AM
  3. Puzzled.
    By silhoutte75 in forum C Programming
    Replies: 13
    Last Post: 01-21-2008, 05:17 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21