Thread: syntax error

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    92

    syntax error

    Hi, sorry it might be stupid to post it but I need some help to track this syntax error, as I can't see it, I think there no error but compiler keeps telling :
    Code:
    .c(27) : error C2143: syntax error : missing ')' before ';'
    .c(27) : error C2059: syntax error : ')'
    .c(70) : error C2143: syntax error : missing ')' before ';'
    .c(70) : error C2059: syntax error : ')'
    and this two functions where I'm having those errors

    First:
    Code:
    void get_weight(void)
    {
    		for(i=0;i<num_packages;++i)
    		{
    			printf("Enter Weight for package#%i:  \n", i);
    			scanf_s("%i", &weight);
    
    			t_weight+=weight;
    			
    			if(t_weight>max_weight)
    				printf("Overload, packages can't be picked up");
    				--num_packages;
    		}
    }

    Second:

    Code:
    void print_reciept(void )
    {
    	printf("\tShipping Receipt\n");
    	printf("\t\tDate: %i/%i/%i\n",month,date,year); 
    	printf("Customer#:          %i\n",customer);
    	printf("No. of Packages:    %i\n",num_packages);
    	printf("\nDeliver Distance: %i\n",distance);
    	printf("\nTotal Weight:     %i\n",weight);
    	printf("\nShipping Charge:  %i\n",charge);
    }
    Thank you.
    Last edited by nynicue; 03-01-2009 at 04:44 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    And what?
    You want us to guess which are lines 27 and 70 ?

    Since the first one is line 27, post the first 30 lines
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Sorry you right I should be more specific, Ok here is a first 33 lines , I marked theline where compiler shows an error

    Code:
    #include <stdio.h>
    	
    #define max_weight 300;
    #define charge 20;
    #define year 2009;
    int i, num_packages, t_num_packages=0;
    int weight, t_weight=0;
    int distance;
    int customer=1;
    int month, date;
    float t_charge;
    
    void get_num_of_packages(void)
    {
    		printf("How many packages: ");
    		scanf_s("%i", &num_packages);
    		t_num_packages+=num_packages;
    }
    
    void get_weight(void)
    {
    		for(i=0;i<num_packages;++i)
    		{
    			printf("Enter Weight for package#%i:  \n", i);
    			scanf_s("%i", &weight);
    
    			t_weight+=weight;
    			
    			if(t_weight>max_weight)	// syntax error			
                            printf("Overload, package can't be picked up");
    				--num_packages;
    		}
    }
    Last edited by nynicue; 03-02-2009 at 06:38 AM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    #define max_weight 300;
    means that
    Code:
    			if(t_weight>max_weight)	// syntax error
    looks like this after preprocessing:

    Code:
    			if(t_weight>300;)	// syntax error
    Any chance you can spot the error?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I don't see your syntax error but be aware that this:

    Quote Originally Posted by nynicue View Post
    Code:
    if(t_weight>max_weight)	
    printf("Overload, package can't be picked up");
    	--num_packages;
    means this
    Code:
    if(t_weight>max_weight)	  { printf("Overload, package can't be picked up"); }
    --num_packages;
    and not this:
    Code:
    if(t_weight>max_weight)	  { 
              printf("Overload, package can't be picked up"); 
              --num_packages;  
    }
    Which means that num_packages will be decremented no matter what -- even if t_weight<=max_weight.

    ps. wow matsp, I won't have guessed that -- but I've never used a semi-colon at the end of a #define
    Last edited by MK27; 03-02-2009 at 07:06 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Thank you all, matsp I wouldn't guess myself that this error because of wrong defined veriable, MK27 thank you for explanation about my if statement, it helped.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by nynicue View Post
    Thank you all, matsp I wouldn't guess myself that this error because of wrong defined veriable, MK27 thank you for explanation about my if statement, it helped.
    And what's worse is that the compiler can't tell you either. The way the preprocessing and the compilation works in a C compiler makes the compiler completely unaware of the fact that what it compiles looked like before the #define.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM