This function determines the number of words in a string.

View versions (1)

Interface

#include <codecogs/strings/word_count.h>

using namespace Strings;

The assumptions involved are:

  • The string is null terminated
  • The words seperation char is only a space and nothing else.

Example 1

#include<codecogs/strings/word_count.h>
void main () {
   char * sz = "The quick     brown fox jumps over the 
lazy           dog.";
   int nWordCount = word_count (sz);
   printf ("The word count is %d", nWordCount);
}

Output:

9

Parameters

szInputString
The null terminated input string

Returns

Number of words in the input string.
GPL Licence — free for non commercial use. See Licence details.