Finding a smaller array within a larger 2D array
I have this code to try and locate a small array within a big array but it seems to crash on the first if statement. Both arrays are dynamically allocated from files and point to a strcuture.
Code:
for (i=0;i<head[1].width-head[2].width;i++) //Looks for possible start postions
{
int wally = 0;
//printf("%d ", i);
for(j=0;j<head[1].height-head[2].height;j++)
{
wally = 1; //Tests if query array is found in main input array
for(qi=0; qi<head[2].height; qi++) //Looks through smaller array for match
{
for(qj=0;qj<head[2].width;qj++)
{
if ((RGBArray[i+qi][j+qj].red != QueryArray[qi][qj].red) || (RGBArray[i+qi][j+qj].green != QueryArray[qi][qj].green)
|| (RGBArray[i+qi][j+qj].blue != QueryArray[qi][qj].blue))
{
wally = 0;
break;
}
}
if(!wally)
break;
}
if(wally)
{
identify_y = j; //Stores j values that match in variable
identify_x = i; //Stores i values that match in variable
printf("%d ", i);
printf("%d ", j);
break;
}
}
}