comparing a value to a array and outputting

i have 3 arrays total, 2 of them i am comparing to see if any of the values match at all, and then i am putting the value that matches into the 3rd array. currently i am trying

int isthere (int match[], int maxmatchLength,
const int vec1[], int vec1Length,
const int vec2[], int vec2Length)
{

for (i=0; i<vec1Length; i++)
if vec1[i]==vec2[i];
vec1[i] = match[i];

}

But this will just match the same values are in the same spot. how do i fix it so that it compares one value in the first array to the whole second array, before going to the next number.
by looping twice... So Do something like this

1
2
3
4
5
6
7
8
9
10
11
int m[6] = {1,2,3,4,5,6};
int b[6] = {1,5,4,6,8,7};

for(int i1 =0; i1 < 6;++i1)
{
 for(int i2 =0; i2 < 6; ++i2)
  {
    if(m[i2] == b[i1])
    cout << "Found";  
  }
}


so your code

1
2
3
4
5
6
7
8
9
10
for (i1=0; i1<vec1Length; i1++)
 {
  for (i2=0; i2<vec2Length; i2++)
   {
     if vec1[i2]==vec2[i1];
     ...
     ...
     ...
    }
 }


you must write the correct vec1Length...... for avoiding some issues in future
Last edited on
Topic archived. No new replies allowed.