char_array[] is "x, a, x, c, x, b, x, a, x, x ,b ,x ,x, x, x"
key_array[] is "a, b, c"
expected return array: "1, 5, 3"
The goal is to print the index of the char_array that matches with key_array. For example, in this case the program has to print "1, 5, 3". It only counts the first index it matches.
Another example would be that
char_array[] is "q, h, e, h, w, e, r, t, l, y, l, l, o"
key_array[] is "h, e, l, l, o"
expected return array: "1, 2, 8, 10, 12"
What I have tried so far is
int index = 0;
for(int i = 0; i < key_array.length; i++)
{
isFound = false;
for(int k = index + 1; k < char_array.length && isFound == false; k++)
{
if(char_array[i] == key_array[k])
{
index = k;
num[j] = index;
isFound = true;
}
}
}
This way, my second example which deals with "hello" works but my first example which deals with "abc" doesn't work.
I started my k with index+1, but I guess I will have to change this from 0 to char_array.length..
Can someone help me with this logic please
break, then repeatindexto 0