1. ## 2 array match

hi,i'm still a beginner in C++, below is a sample program n its output, i would like to know how do I limit the match recorded to only once? Refering 2 the 2nd line output it found a match at array1 element 1 and array2 element2. But it finds the same match again in the 3rd line output at array2 element2.
When a match is found, the scanning shouldn't repeat the matcher array1 and the matched at array2, it should proceed for the new next consequent array's element.
Thanx to anyone who would be able to shed some light in it.thanx alot.

#include <stdio.h>
#define MAX 5
int main(void)
{
int i, j, array1[5], array2[5];

array1[0] = '1';
array1[1] = '0';
array1[2] = '0';
array1[3] = '7';

array2[0] = '1';
array2[1] = '5';
array2[2] = '0';
array2[3] = '2';

for (i=0;i<MAX-1;i++) {
for(j=0;j<MAX-1;j++) {
if (array1[i] == array2[j])
{
printf("we found a match at array1 element %d and array2 element %d \n", i, j);

}
}
}

return 0;

}

Output screen:
we found a match at array1 element 0 and array2 element 0
we found a match at array1 element 1 and array2 element 2
we found a match at array1 element 2 and array2 element 2

thanx again

2. im not sure i understand your question but try this...

Code:
```for (i=0;i<MAX-1;i++) {
for(j=0;j<MAX-1;j++) {
if (array1[i] == array2[j])
{
printf("we found a match at array1     element %d and array2 element %d \n", i,  j);
break;
}
}
}```

3. thank u, for the help...how do i make only the adjacent array rows only to match

array1[0] = '1'; array2[0] = '1';
array1[1] = '0'; array2[1] = '5';
array1[2] = '0'; array2[2] = '0';
array1[3] = '7'; array2[3] = '2';

i only want it to match once,and its adjacent rows...thank you for the help to be rendered.

4. If I understand correctly:
Code:
```for (i=0;i<MAX-1;i++)
{
if (array1[i] == array2[i])
{
printf("we found a match at array1 element %d and array2 element %d \n", i, i);
}
}```

5. thanx jawib,,it does wat i want coz both arrays 1 & 2 were declared previously...wat if i only had somethin like below, where the arrays re stored in a image buffer, i had to specify them, if like this how do i find the match for the adjacent array rows.thanx 2 al for the help. Here for every i & j / x & y there is a value called pixelv. So here sinz both i & x re fixed, only j & y varies. how do i find a match once for every pixelv at every adjacent j & y?

MbufGet2d(MilImage, 0L, 0L, IMAGE_WIDTH, IMAGE_HEIGHT, &pixelv )

for(j=254;j<401;j++)

{
for(y=144;y<291;y++)

{

x=200; i=270;

if(pixelv[i][j]==pixelv[x][y])

{
fprintf(fptr,"\t%d %d %d %d\n",j ,y ,pixelv[i][j] ,pixelv[x][y]);
break;
}
}
}

6. MbufGet2d(MilImage, 0L, 0L, IMAGE_WIDTH, IMAGE_HEIGHT, &pixelv )

for(j=254;j<401;j++)

{
for(y=144;y<291;y++)

{

x=200; i=270;

if(pixelv[i][j]==pixelv[x][y])

{
fprintf(fptr,"\t%d %d %d %d\n",j ,y ,pixelv[i][j] ,pixelv[x][y]);
break;
}
}
}

How do i make the adjacent match between j & y for the same pixelv value...if both the adjacent value for j & y has the same value of pixelv than it should print out per the requirement.
Hope someone could shed some light here..thank you.