Very easy issue with strstr
Hi I have a piece of code that's supposed to find and change all instances of words in a sentence. Here's what it pretty much looks like:
Code:
while(replace = strstr (p, from)){
while(*to){
*replace = *to;
replace++;
to++;
}
}
Anyways, replace, to, p, and from are all pointers.
p points to an array containing the original sentence: i.e. "that guy is a great guy"
from points to the word to be changed: i.e. "guy"
to points to the word that from is changed to: i.e. "girl"
replace just points to what strstr returns (as shown)
Now for some reason my program is infinite looping. I assume because replace keeps being pointed to the first instance. I have used a print statement to check and receive:
"that girl is a great guy"
repetitively when using that as my test sentence.
How can I fix this issue?