The variable i
, which represents the offset with respect to the first element, should start at zero:
int i = 0;
The loop condition is checking whether the value of the array element is equal to the value of the array element at the end.
while(*(left + i) != *end)
The correct version is the following:
while(left + i != end)
which checks if the pointer (left + i)
has reached the end.