title: How do I find the number of times an array of characters appers in another array of characters?
body: <p>I'm given 2 arrays <code>sir</code> and <code>sub</code>. I'm supposed to find the number of times <code>sub</code> is contained in <code>sir</code> by using the <code>strstr</code> function in library <code>&lt;cstring&gt;</code> and deleting the first letter. For example, <code>sir</code> is <code>omtatatatarshta</code> and <code>sub</code> is <code>tat</code>. I can see that <code>sub</code> first appears biginning with the third letter and I delete that letter from <code>sir</code> so next time I search for <code>sub</code> in <code>sir</code> I get a different appearence. But I get very confused with managing the fact that <code>x</code>, where <code>x=strstr(sir, sub);</code>, is a pointer.
  <code>nr</code> is the variable that shows the number of times <code>sub</code> can be found <code>sir</code>.</p>
  
  <p>First I've tried to do a <code>for</code> like this:
  <code>for(i=x; i&lt;strlen(sir); i++) sir[i]=sir[i+1];</code> and I got the error <code>invalid comparison between 'char*' to 'int'</code>. Then, after looking at some code on the internet I tried writing it like this: <code>for(char *x; *x!='\0'; *x++) *x=*(x+1);</code> I got no error with this but I don't get any result either.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  ifstream f("info.in");
  char sub[20], sir[100];
  char* x;
  int main()
  {
      int nr=0, i;
      f &gt;&gt; sub;
      f &gt;&gt; sir;
      cout &lt;&lt; sir;
      x = strstr(sir, sub);
      while (x) {
          nr++;
          for (char* x; *x != '\0'; *x++)
              *x = *(x + 1);
          x = strstr(sir, sub);
      }
      cout &lt;&lt; nr;
      return 0;
  }
  </code></pre>
  
  <p>In my examples <code>sub</code> is <code>tat</code> and <code>sir</code> is <code>omtatatatarshta</code>and the answer should be 3, as you can find <code>tat</code> in <code>omtatatatarshta</code> three times.
  As I've said, I get no result with my code.</p>