title: How does this C function count the number of words in a string?
body: <p>I need some help to understand how does the <code>countWords</code> function work in the program below.</p>
  
  <p>It is all explained in "Programming in C" written by Stephen Kochan but I didn't get how it works when it comes to "lookingForWord" and "++wordCount" in <code>countWords</code> function!</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  
  //function to determine if a character is alphabetic
  bool alphabetic (const char c)
  {
      if ( (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || ( c &gt;= 'A' &amp;&amp; c &lt;= 'Z'))     
          return true;
      else
          return false;
  }
  
  // function to count the number of words in a string
  int countWords ( const char string[])
  {
      int i, wordCount = 0;
      bool lookingForWord = true, alphabetic ( const char c);
  
      for ( i = 0; string[i] != '\0'; ++i)
          if (alphabetic(string[i]) )
          {
              if ( lookingForWord )
              {
                  ++wordCount;
                  lookingForWord = false;
              }
          }
          else
              lookingForWord = true;
  
      return wordCount;
  }
  
  int main ( void)
  {
      const char text1[] = {"Well, here goes."};
      const char text2[] = { "And here we go... again"};
      int countWords (const char string[]);
  
      printf( " %s - words = %i\n", text1, countWords (text1));
      printf( " %s - words = %i\n", text2, countWords (text2));
  
      return 0;
  }
  </code></pre>