You have a few issues in your code, the ones I can spot right away are:
if(str[0]='\0')
- this is an assignment, not a comparison. Your entire string will be replaced with \0
-characters - no characters will be skipped because this:
if(str[0]!='x'||str[0]!='X')
is always true. Ask yourself if x
is different from x
(false) OR X
(true). False or true = true.
The check should be implemented something like (str[0] != 'x' && str[0] != 'X')
.
Edit: One more issue.
The overall logic will not work (-ish). The part where you run through the string and compress it is correct enough. But you try to run to the end and then print the string, however at that point you are only holding the end of the string (the null termination), so no matter what else you have done you will only print that (aka. print nothing).
Instead, once you are done compressing the x
s out of the string, you need to return to the beginning of the string and then print that. The easy way is to print in main
, or you can split your function into an outer+inner function like:
void outer_removeX(str) {
removeX(str);
print(str);
}
Or you could add an extra variable to the recursion that allows you to return to the first call in the chain and then print there.
However, only printing the end will not work.