So here’s my code
int find_h(int i, int j, int current[N+1][N], int goal[N+1][N])
{
int sum=0;
int a, b;
int cp[N*3], gp[N*3];
for(a=0;a<N;a++)
{
for(b=0;b<N;b++)
{
cp[4*a+b]=current[a][b];
gp[4*a+b]=goal[a][b];
printf("b = %d\n", b);
}
printf("\n");
}
return sum;
}
N=4 and current and goal are filled with the numbers from 0 to 15 inclusive, only appearing once each.
It loops fine the first 3 iterations (until a=3) but then it keeps outputting b = 0 forever.
Thanks
I don’t know what you want to do, but I’ll tell you something:
cpandgpare too much small. As written, they should be bigN * Ninstead ofN * 3(== 12).Now, here
cp[4*a+b]you should have writtenN*a+b. IfN == 4then it’s the same. Otherwise…And it isn’t clear:
int current[N+1][N]this will be (withN == 4) a 20 array element. You are then copying in a linearized array ofN * Nelements (or perhapsN * 3, see above)…