- #1
crimsondancer
- 1
- 0
I was reading my textbook to study for a test in my C++ class and I cam across this question and the answer is not in the book. I'm afraid I might need to know how to do something like this for my test and there isn't an example of one like it in my book. I'm not sure how to do it so I don't have any code to show you guys. I was wondering if anyone knew the answer to this question. Thanks!
Here it is:
Substring function
Write a program that finds a substring inside a string. Main program asks users to type a string and then a substring. Then, program calls a subfunction int mystrstr(char *str, char *substr). Inside the mystrstr subroutine, program searches substring substr in the string str and returns the starting position of the substring in the string. If the substring is not located in the string, then subroutine return -1. After searching the position, main program prints out the string from the position to the end of string of the string. e.g. string: "C++ program is really fun", substring: "program", Then, your program will print "program is really fun"
Here it is:
Substring function
Write a program that finds a substring inside a string. Main program asks users to type a string and then a substring. Then, program calls a subfunction int mystrstr(char *str, char *substr). Inside the mystrstr subroutine, program searches substring substr in the string str and returns the starting position of the substring in the string. If the substring is not located in the string, then subroutine return -1. After searching the position, main program prints out the string from the position to the end of string of the string. e.g. string: "C++ program is really fun", substring: "program", Then, your program will print "program is really fun"