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?
#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