Hi , I have a small 2d array and I want to check if it exists in a bigger 2d array. I have coded it but I don't know what am I doing wrong cause even if exists it won't detect it. 2 arrays are PI and NPI. PI is the bigger and NPI is the smaller one.

for (int i=0;i<SCREEN_WIDTH-width;++i)
            {
                for (int j=0;j<SCREEN_HEIGHT-height;++j)
                {
                    boolean isequal = true;
                    for(int qqq=i;qqq<i+width;++qqq)
                    {
                        for (int kkk=j;kkk<j+height;++kkk)
                        {
                            if (PI[qqq][kkk]!=NPI[qqq-i][kkk-j]) isequal = false;
                            if (isequal == false) 
                            {
                                    qqq =  i + width + 1;
                                    kkk = j + height + 1;
                            }
                        }

                    }
                    if (isequal==true)
                    {
                        MidX = i;
                        MidY = j;
                        return;
                    }
                }
            }

It looks like we're mssing information, and I feel like a visual will illuminate the problem faster then staring at code.

After line 9, add cout << PI[qqq][kkk] << " " << NPI[qqq-i][kkk-j] << endl;,
and after line 18 (before if (isequal==true)) add cout << "new row" << endl; After line 24, add cout << "Moving box down once." << endl; And after line 25, add cout << "Moving boc left once" << endl;.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.