NO

Author Topic: Getting error 2001  (Read 3562 times)

dantwah

  • Guest
Getting error 2001
« on: February 25, 2009, 03:02:30 PM »
hy, i'm new with pelles and c coding. I've got a program which you could change to your specific needs. It is used to make a magical square. Originally for a 4x4, but i changed it to 5x5.
Now i get a few errors:
Building victorian 5x5.obj.
C:\Documents and Settings\xxxxxx\Bureaublad\victorian 5x5.c(59): warning #2027: Missing prototype for 'exit'.
C:\Documents and Settings\xxxxxx\Bureaublad\victorian 5x5.c(61): warning #2096: Missing return value.
C:\Documents and Settings\xxxxxx\Bureaublad\victorian 5x5.c(218): error #2001: Syntax error: expected ';' but found 'if'.
C:\Documents and Settings\xxxxxx\Bureaublad\victorian 5x5.c(254): error #2001: Syntax error: expected ';' but found 'return'.
*** Error code: 1 ***
Done.


and this is the program(allready changed to 5x5)
Does someone know what to change to loose the errors?


Code: [Select]
#include <stdio.h>

#include <time.h>



#define bool   int

#define true   1

#define false  0



int  board[130];

int  solution;



bool check130(int a, int b, int c, int d, int e);

bool validboard(void);

void initSumIt(void);

int  place(int s, int p);

void printboard(void);

void stone(int s);



int main(int argc, char** argv)

{

   time_t s, e;

   

   initSumIt();

   time(&s);

   stone(25);

   time(&e);

   printf("started at: %s\n", asctime(localtime(&s)));

   printf("ended at:   %s\n", asctime(localtime(&e)));

   printf("run for %.0f seconds.\n", difftime(e, s));

   exit(0);

}



bool check130(int a, int b, int c, int d, int e)

{

   int s;



   s = board[a] + board[b] + board[c] + board[d] + board[e];

   if ((board[a]==0) || (board[b]==0) || (board[c]==0) || (board[d]==0) || (board[d]==0))

   {

      if (s<130)

      {

         s=130;

      }

      else if (s==130)

      {

         s=0;

      }

   }

   return(s==130);

}



bool validboard(void)

{

   #define strict_checks          true

   #define exclude_mirrors        false

   #define include_extra_checks   false



   #define check(a,b,c,d,e) if (ok) ok=(check130(a-1,b-1,c-1,d-1,e-1))

       

   bool ok;



   ok = true;



#if strict_checks

   /* If you use more strict condition;                           */

   /* then you can obtain the most fundamental three squares.     */



   if ((board[0] > 0)&&(board[1] > 0)&&(board[3] > 0)&&(board[4] > 0)&&(board[12] > 0))

   {

      ok =(board[0]==1) &&

          (board[1] < board[3]) &&

          (board[4] < board[12]) &&

          (board[3] < board[12]);

   }

#endif /* strict_checks */



#if exclude_mirrors

   /* In order to reject the mirror and/or rotational image       */

   /* you had better to use a condition such as                   */

   /* If you use the condition the result may becom 48 (= 384/8). */



   if ((board[0] > 0)&&(board[3] > 0)&&(board[12] > 0)&&(board[15] > 0))

   {

     ok = (board[0] < board[3]) &&

          (board[0] < board[12]) &&

          (board[0] < board[15]) &&

          (board[3] < board[12]);

   }

#endif /* exclude_mirrors */



   /*  1   2   3   4   5 */

   /*                */

   /*  16   17   18   19   20 */

   /*                */

   /*  21   22   33   34   35 */

   /*                */

   /* 37   38   39   40   41 */
   
   /*                */
   /* 42   43   44   45   46 */



   /* It is OK to check only three of each group of four tests. */

   /* The total som is 5*130 so if four tests succeed the fifth will also! */



   check( 1,  2,  3,  4, 5);

   check( 16, 17, 18, 19, 20);

   check( 21, 22, 33, 34, 35);
   
   check(37, 38, 39, 40, 41)

   /*check(42, 43, 44, 45, 46);*/

   

   check( 1,  16, 21, 37, 42 );

   check( 2, 17, 22, 38, 43);

   check( 3, 18, 33, 39, 44);

   check( 4, 19, 34, 40, 45)
   /*check( 5, 20, 35, 41, 46);*/

   




#if include_extra_checks

   /* The following checks are, strictly spoken, not needed */

   /* but they will speed up the process remarkably by forcing */

   /* to backtrack in an early stage */

   /* Try it by changing true to false and note the difference! */

   /* 41 sec. versus 172 sec. on my machine. */

   



#endif /* include_extra_checks */



 

   return(ok);

}



void stone(int s)

{

   int p;

   

   if (s>0)

   {

      for (p=place(s,0); p > 0; p=place(s,p))

      {

         if (validboard()) stone(s-1);

      }

   }

   else

   {

      printboard();

   }

   return;

}



int place(int s, int p)

{

   int i;



   if (p > 0) board[p-1]=0;

   i = p + 1;

   while ((board[i-1] > 0) && (i < 16)) i++;

   if ((board[i-1]==0) && (i <= 16))

   {

      board[i-1] = s;

   }

   else

   {

      i = 0;

   }

   return(i);

}



void printboard(void)

{

   #define printline(r) printf("   %2d %2d %2d %2d\n", board[r*5], board[r*5+1], board[r*5+2], board[r*5+3], board[r*5+4])



   printf("Solution: %i\n", ++solution);

   printline(0);

   printline(1);

   printline(2);

   printline(3);

   printline(4);

   printf("\n");

   return;

}



void initSumIt(void)

{

   int i;

   for(i = 0; i < 25; i++) board[i] = 0;

   solution = 0;

   return;

}






Many thanks,
Dant


« Last Edit: February 25, 2009, 06:13:41 PM by dantwah »

Offline DMac

  • Member
  • *
  • Posts: 272
Re: Getting error 2001
« Reply #1 on: February 25, 2009, 04:59:43 PM »
Dant,

Your problem is that you are missing the ';' following your 'check()' macro in at least two places.

Code: [Select]
/* It is OK to check only three of each group of four tests. */

   /* The total som is 5*130 so if four tests succeed the fifth will also! */



   check( 1,  2,  3,  4, 5);

   check( 16, 17, 18, 19, 20);

   check( 21, 22, 33, 34, 35);
   
   check(37, 38, 39, 40, 41)  //<= OOPS

   /*check(42, 43, 44, 45, 46);*/

   

   check( 1,  16, 21, 37, 42 );

   check( 2, 17, 22, 38, 43);

   check( 3, 18, 33, 39, 44);

   check( 4, 19, 34, 40, 45)  //<= Oh Oh, not again!
   /*check( 5, 20, 35, 41, 46);*/


The giveaway with these type of errors is
Quote
C:\Documents and Settings\xxxxxx\Bureaublad\victorian 5x5.c(218): error #2001: Syntax error: expected ';' but found 'if'

Right away I look for a single line if without a statement termination.

Since these are usually obvious I immediately suspect a macro.

A quick glance at the code yielded the likely macro:

Code: [Select]
   #define check(a,b,c,d,e) if (ok) ok=(check130(a-1,b-1,c-1,d-1,e-1))

the rest quickly fell into place.

In C it is best to fix the first and / or second error that pops up and then recompile.  Usually the rest will go away.

One more thing.

When posting code using the insert code tool button "#" will give you the format tags to make the snippet easier to read.

Regards,
DMac
No one cares how much you know,
until they know how much you care.

dantwah

  • Guest
Re: Getting error 2001
« Reply #2 on: February 25, 2009, 06:16:06 PM »
Aaa thanks verry much ;D it was a stupid mistake ;) and also thanks voor the #, changed it immediatly