Im trying to implement a function that searches a multidimensional array finds out if a value is in it, then moving that function. My search function
bool search(int value, int values [][d], int n)
{
bool In = false;
//d is an it that is the maximum length and height
//e.g 3x3 or 4x4 as in the image below
for(int row=0; row<d; row++)
{
for(int col=0; col<d; col++)
{
if(values[row][col] == value)
{
//checking if this loop is executed
printf("EXECUTED!! :) \n");
In=true;
}
printf("Row:%i & Col%i: %i \n",row,col,values[row][col]);
}
}
//Usleep for debugging purpouses
// as another function clears the screen
usleep(50000000);
if(In==true){return true;}
if(In==false){return false;}
}
This is what is printed which is weird as to print the 4x4 box above i used the same array and the search function does not alter the array in anyway. This is my "move" function
bool move(int tile)
{
if(search(tile,board,d))
{
printf("please execute this code pretty please clang\n");
return true;
}
else
{
printf("NOO\n");
return false;
}
}
And here is the function that initilazes the variable in the first place
void init(void)
{
bool even;
if((d & 1) == 0)
{
even = true;
}
else
{
even = false;
}
int value = d*d - 1;
for(int row =0; row<d; row++)
{
for(int col=0; col<d; col++)
{
board[row][col]=value;
value--;
}
}
//for this game to work if d is even the values of the third
// and second last arrays must be switched
if(even==true)
{
int temp = board[d-1][d-2];
board [d-1][d-2] = board[d-1][d-3];
board [d-1][d-3] = temp;
}
}
EDIT: Here is the pastebin for the full code http://pastebin.com/yS8DDEqZ Note Cs50 is a custom libary that was implemented by the class im taking, it defines a string a helper functions which get user input GetInt() etc.