I am trying to use strstr
to see if a string appears in another string. For example, I have a string like: -path-elonmusk-bin
. I want to replace a part of it or -path-elonmusk
to a "$"
. So the updated path would be: $/bin
.
I am able to change it to "$"
but instead of changing the part, it changes the whole string. Is there a way to maybe split the string so it returns the rest of the path.
Here is my code:
char *home = "-path-elonmusk";
char *path = "-path-elonmusk-bin-asksks";
char *strmatching = strstr(path, home);
if(strmatching == path) {
strcpy(path, "~");
}