Find a word in a sentence, both of which are to be entered by the user. Extra spaces in sentence, at the beginning and the end are to be ignored. Extra spaces in sentence and word both, at the beginning and the end are to be ignored. Extra spaces in sentence, anywhere are to be ignored.For the sentence, you cannot remove spaces from the sentence in a separate loop.
- Sentence: “ This is me “
Word: “This”
Output: Word found - Sentence: “ This is me “
Word: “ me ”
Output: Word found - Sentence: “ This is me “
Word: “ is ”
Output: Word found
I used an array index. Basically the same code except that the char * p can be replaced with int x so
for (int x=0; str[x]; ++x) {
if (str[x] == ‘ ‘) continue;
// do something with str[x]
}
New contributor