Just mentioning also that in the OP's original code,
Code:
if (sentence[i + j] != word[j])
can cause an out-of-bounds read