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 an index char_arraythat matches key_array. For example, in this case, the program should print "1, 5, 3". It only considers the first index that it matches.
Another example:
char_array[] is "q, h, e, h, w, e, r, t, l, y, l, l, o"
key_array[] there is "h, e, l, l, o"
expected return array: "1, 2, 8, 10, 12"
I tried so far
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;
}
}
}
So my second hello example works, but my first abc doesn't work.
k index+1, , 0 char_array.length..
- , ,