Question: C-string::find In this lab, you'll be writing a find() function that accepts two C-style strings (const char*, terminated with '0'), an input string and a

C-string::find

In this lab, you'll be writing a find() function that accepts two C-style strings (const char*, terminated with '\0'), an input string and a target string, and it should return a vector. The elements in this vector should be pointers to every place the target string shows up inside the input string.

For example, if the target string is "I" and the input string is "In three words I can sum up everything I've learned about life: it goes on.", find() should return a vector with pointers to the "I" of "In", the "I" before "can", and the "I" of "I've" (but not the "i" of "it").

#include #include #include #include using namespace std;

vector find(const char* input, const char* target) { vector ret; // add solution here return ret; }

int main() { string str, tgt; getline(cin, str); getline(cin, tgt); vector ptrs = find(str.c_str(), tgt.c_str()); for (int i = 0; i < ptrs.size(); i++) cout << "Location #" << i+1 << " (at pos " << ptrs[i] - str.c_str() << "): " << ptrs[i] << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!