title: How can I recursively count the number of non-whitespace characters in a string using C?
body: <p>The main problem with this program is that it won't count the number of whitespaces in a string, even though it's supposed to decrement the count if it encounters a whitespace (it starts out with count set to the string's length). Am I not checking for whitespaces correctly (by checking for ' '), or is there something wrong with my recursion cases?</p>
  
  <pre><code># include &lt;stdio.h&gt;
  # include &lt;string.h&gt;
  
  // function to reverse string and count its length
  int rPrint(char *str, int count)
  {
     if(*str)
     {
         if(*str != ' ')   
             rPrint(str+1, count);
         else
             rPrint(str+1, count - 1);
  
         printf("%c", *str);
     }
     return count;
  }
  
  int main()
  {
     char string[28] = "";
     int count = 0;
  
     printf("Please enter a string: ");
     gets(string);
  
     count = rPrint(string, strlen(string));
  
     printf("\nThe number of non-blank characters in the string is %d.", count);
  }
  </code></pre>