title: Using strchr() to count occurrences of a character in a string
body: <p>I'm almost finished with the class semester, and I'm working on an assignment to write a function to find the number of a certain character in a string, given the function prototype the teacher assigned. I know I must be doing something stupid, but this code is either locking up or looping indefinitely in my function.</p>
  
  <p>It is an assignment, so I'm not looking for anyone to do my homework for me, but merely to point out where I'm wrong and why, so I can understand how to fix it. I would appreciate any help that you are willing to give.</p>
  
  <p>Here's the code I've written:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  int charCounter(char* pString, char c);
  
  int main(void)
  {
      char* inpString = "Thequickbrownfoxjumpedoverthelazydog.";
      int charToCount;
      int eCount;
  
      eCount = 0;
      charToCount = 'e';
      eCount = charCounter(inpString, charToCount);
      printf("\nThe letter %c was found %d times.", charToCount, eCount);
  
      return 0;
  } // end main
  
  int charCounter(char* pString, char c)
  {
      int count = 0;
      char* pTemp;
  
      do
      {
          pTemp = strchr(pString, c);
          count++;
      }
      while(pTemp != NULL);
  
      return count;
  } // end countCharacter
  </code></pre>