I have runtime error and I don’t know what’s the reason .
void replace(char *str, char ch){
int i=0;
while(*(str+i) != '\0'){
if(*(str+i) == ' '){
*(str+i) = ch; // I doubt in this line
}
i++;
}
cout << str << "\t";
}
int main(){
replace("Hello World",'_');
return 0;
}
You cannot modify “Hello World” which is a constant, read-only string.
It will work better like this: