c type string

Write a program that will allow the user to input a string and perform

various editing functions on it



NOTE: You must use C type strings for this assignment





Requirements specification:



Write a program that will ask the user to enter a string. It

will then regard that string as a worked-on string and allow the user to

perform the following editing functions on it:



s - search



i - insert



a - append



d - delete



a - append



d - delete



r - replace



e - exit





s -search



This option will allow the user to search for a specified string in the

worked-on string. If the string is found, it will display the starting index

(position) of the searched string in the worked-on string.





I - insert



This option will allow the user to insert a string at a specified index

in the worked-on string.





a - append



This option will allow the user to append (add) a specified string at

the end of the worked-on string.





d - delete



This option will search for a specified string in the worked-on string.

If the specified string is found, it will eliminate it from the worked-on

string.





r - replace



This option will allow the user to replace an existing string in the

worked-on string with a specified string.





e - exit



This option will result in ending the program.
That sound like a really interesting homework problem.
This is.. I do not know where to start or how to attempt this homework program. Hoping someone can help me
Idk about anyone else but I am not going to help you unless you atleast have put some effort into it
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().

Topic archived. No new replies allowed.