title: C version of strpos and substr?
body: <p>I'm really surprised I can't figure out a way to do this effectively. I've tried <em>strstr</em>, a combination of things with <em>sscanf</em>, and nothing seems to work the way I would expect it to based on my experience in other languages.</p>
  
  <p>I have a char of "<strong>ABCDEFG HIJ K BEGINTheMiddleEND LMNO PQRS</strong>". I do not know where "<strong>BEGINTheMiddleEND</strong>" is in the string, and I would like to end with a char that equals "<strong>TheMiddle</strong>" by finding the occurrences of "<strong>BEGIN</strong>" and "<strong>END</strong>" and grabbing what is in between.</p>
  
  <p>What is the most efficient way to accomplish this (find and sub-string)?</p>
  
  <p>Thanks!</p>
  
  <p>-- EDIT BASED ON ANSWERS --</p>
  
  <p>I have tried this:</p>
  
  <pre><code>char *searchString = "ABCDEFG HIJ K BEGINTheMiddleEND LMNO PQRS"
  char *t1, *t2;
  t1 = strstr(searchString, "BEGIN");
  t2 = strstr(t1, "END");
  </code></pre>
  
  <p>But something must be wrong from a pointer standpoint as it doesn't work for me. Strstr only takes two arguments, so I'm not sure what you mean by starting at the previous pointer. I'm also not sure how to then use those pointers to substring it, as they are not integer values like strpos returns, but character pointers.</p>
  
  <p>Thanks again.</p>
  
  <p>-- EDIT WITH FINAL CODE --</p>
  
  <p>For anyone else who hits this, the final, working code:</p>
  
  <pre><code>char *searchString = "ABCDEFG HIJ K BEGINTheMiddleEND LMNO PQRS"
  char *b = strstr(searchString , "BEGIN");
  char *e = strstr(b, "END");
  int offset = e - b;
  b[offset] = 0;
  </code></pre>
  
  <p>Where "b" is now equal to "BEGINTheMiddle". (which as it turns out is what I needed in this case).</p>
  
  <p>Thanks again everyone.</p>