You have to put a terminating zero character at the end of s1
:
s1[strlen(s)] = 0;
Also, instead of executing the "expensive" strlen(s)
many times you should calculate the length just once by putting it to a variable and then you should use the variable instead of the strlen(s)
call:
size_t len = strlen(s);
You should free the allocated memory block after printing its string content by calling the free()
function call.
In this case you don't have to forward declare inverseString()
and be a bit more brave and use a larger buffer size, instead of 30 lets use a more common value, for example 0x100.