This code (for goodness sake, put some spaces in there)
for(i = len - 1; prefix[i] >= 0; i--)
will end up using a negative index (
i == -1
and below) until a
prefix[i]
that is negative is reached. When that will happen is unpredictable, because you're looking at memory that is out-of-bounds for the
prefix
array. Try this instead:
for(i = len - 1; i >= 0; i--)