Make each action (insert, delete, replace, search, etc.) a function. Start by thinking about the function and writing a prototype for it.
Note that some of these operations will be creating a new string, so you will need to think about where the new string is stored. Also, what happens to the old string (hint: you may need to delete it).
Also notice that some of the functions can us other functions if you do it right. For example, the "delete" function has to search for the string to delete, which is a whole lot like the "search" function. My advice is to separate the "functionality" from the "presentation". For example, your search function might take the input string and search string as parameters, and return the index of the search string, or -1 if it isn't found:
int search(const char *str, const char *pattern);
And when searching, your main program will call this and output the result:
1 2 3 4 5 6
|
int index = search(inputString, searchString);
if (index>=0) {
cout << "found " << searchString << " at location " << index << end;
} else {
cout << "Can't find " << searchString << endl;
}
|
Now your delete function can also use search().