Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Program from C++ text book

  1. Mar 25, 2010 #1
    I was reading my text book 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"
  2. jcsd
  3. Mar 25, 2010 #2


    Staff: Mentor

    What have you tried?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook