There are several problems which I can spot immediately.
in line 4, you access your array at loc without first checking if loc is within bounds. If loc is invalid, it could cause your program to crash.
in line 9, the first time the for loop is called, it will try to move the string at position 0 to position -1, which is also a bounds violation.
You should rewrite the function to do the bounds checking first. Also, you can simplify the function such that you only need one for loop. You want to loop from the position after loc to the end of the array.