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

Srting inside another string ?

  1. Aug 24, 2009 #1
    Hello every body..

    are you okey..

    i have a question in C about :

    how can i search a string inside another string and count the number of the occurrences of that string ?

    i think the problem is in counting

    is there any suggestion ?
  2. jcsd
  3. Aug 24, 2009 #2
    You can use substr to find the first instance of a substring within a string. Repeatedly call this function on the new starting position until it fails, to count the number of occurrences.
  4. Aug 24, 2009 #3
    I think you mean strstr not substr.
  5. Aug 24, 2009 #4
    Yeah, messed that up...in C++ you would use string.find and string.substr, but in C you have strstr.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook