How to fix this? Why the compiler claims of it if I am using the variable in another code parts?
void replace(char ** src, const char s, const char replace) {
while(*(*src) != '\0') {
if(* (*src) == s) {
news[size] = replace;
} else {
news[size] = *(*src);
}
*(*src) ++; // the error line
size++;
}
*src = news;
}
When you do
*(*src)++you’re basically dereferencingsrc, then doing a postfix increment on the pointer, then dereferencing the pointer. It’s a bug. You’re not using the final value, which is why the compiler warns you.What you really want is
(**src)++; i.e. dereference twice and then increment.