title: Counting number of occurrences of a char in a string in C
body: <p>I have the string <code>str</code></p>
  
  <pre><code>char *str = "100.10b.100.100";
  </code></pre>
  
  <p>I want to count the occurrences of <code>'.'</code> in <code>str</code>, preferably a one-liner. (If possible no loops)</p>
  
  <p>My approach would be the standard <code>strchr</code>:</p>
  
  <pre><code>  int i = 0;
    char *pch=strchr(str,'.');
    while (pch!=NULL) {
      i++;
      pch=strchr(pch+1,'.');
    }
  </code></pre>