Answer the question
In order to leave comments, you need to log in
What algorithm to apply?
Exercise
Implement
{
}
Answer the question
In order to leave comments, you need to log in
It's more like your C than C++.
And in C++ there is std::string with for example find method www.cplusplus.com/reference/string/string/find
return ri;
return -1;
The simplest solution is this:
You loop through the source string and compare the current character with the first character in the Pattern. Once they match (let's say at position i), you loop over pattern and test str[i+offset] to be equal to the current character in pattern, where offset is the current offset in pattern. If any of the characters does not match, then you return to the first loop and continue working with the character str[i+1].
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question