# Thread: Finding A Smaller Array Within A Bigger Array (2D)

1. ## Finding A Smaller Array Within A Bigger Array (2D)

I've got two 2D arrays declared and I want to write some code to find the smaller one within the bigger one. Any tips on how this could work? I know it involves something like looping the values of the bigger array, then the smaller one. Thanks for any help.

2. You start by drawing the problem out on paper, then figuring out what you might need.
Code:
```int large[4][4] = {
{  1,  2,  3,  4 },
{  5,  6,  7,  8 },
{  9, 10, 11, 12 },
{ 13, 14, 15, 16 }
};
int small[2][2] = {
{  7,  8 },
{ 11, 12 },
};```
Your first exercise is write code that finds small[0][0] somewhere in large.

3. I've tried this based on another post I've found on this subject. Where head[1].height/width is for the big array and head[2].height/width is for the smaller (query) array. i and j are width and height for the big array and qi and qj are width and height for small array...
Code:
```for (j=0;j<head[1].height-head[2].height;j++)
{
{
QueryArray[j][i] != NULL;

{
{
{
QueryArray == NULL;
break;
}
}

if(!QueryArray) break;
}
if(QueryArray) return;
}
return;
}```

4. At some point you need to be able to write your own code from first principles.

Not just repost "found" code.

Especially when said "found" code is full of nonsense.

5. Well if I'm stuck I generally look it up and repurpose found code to better understand it so I can do it myself.

6. Though I believe the for loops in the code are at least correct.