void subtract_array(int* a, std::size_t& lenA, int* b, std::size_t lenB) {
lenA = a - std::remove_if(a, a + lenA, [&](int val){ return std::count(b, b + lenB, val); });
}
However, in your case, your problem is that you are giving the wrong letters for a and b in line 4 - you are iterating over 'a' with 'j' not 'i', and the other way round for 'b'.
You could make a third array in the function, then copy all values of a to that array if they don't appear in b. Then return that array. I wouldn't change a at all.
EDIT: You would have to calculate the length of the third array before that though. Just count each element of a which does not appear in b.
EDIT 2: Just seeing, you don't use a function, I would though.