title: Function to count the amount of times two string match in C
body: <p>I'm trying to find how may times two string matches in c, if we have two or more stars, multiple string combination can be suitable. e.g <code>"abcdb"</code> &amp; <code>"*b*"</code> matches two times. my current code works but it returns four. I don't what I am missing here.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int nmatch(char *s1, char *s2) {
      if (*s1 != '\0' &amp;&amp; *s2 != '\0' &amp;&amp; *s2 == '*' &amp;&amp; (*s2 + 1) != *s1) {
          return nmatch(s1 + 1, s2) + 1;
      }
      if (*s1 == *s2) {
          return nmatch(s1 + 1, s2 + 1);
      }
      if (*s1 == *s2 &amp;&amp; *s1 == '\0' &amp;&amp; *s2 == '\0') {
          return 0;
      }
      return (1);
  }
  
  int main() {
      char ap[] = "abcd";
      char ab[] = "*b*";
      printf("%d", nmatch(ap, ab));
      return 0;
  }
  </code></pre>