title: find the maximum number of words in a sentence from a paragraph with C++
body: <p>I am trying to find out the maximum number of words in a sentence (Separated by a dot) from a paragraph. and I am completely stuck into how to sort and output to stdout.</p>
  <p>Eg:
  Given a string S: {&quot;Program to split strings. By using custom split function. In C++&quot;};</p>
  <p>The expected output should be : 5</p>
  <pre><code>#define max 8 // define the max string  
  
  string strings[max]; // define max string  
  string words[max];
  int count = 0;
  
   
  void split (string str, char seperator)  // custom split() function 
  {  
      int currIndex = 0, i = 0;  
      int startIndex = 0, endIndex = 0;  
      while (i &lt;= str.size())  
      {  
          if (str[i] == seperator || i == str.size())  
          {  
              endIndex = i;  
              string subStr = &quot;&quot;;  
              subStr.append(str, startIndex, endIndex - startIndex);  
              strings[currIndex] = subStr;  
              currIndex += 1;  
              startIndex = endIndex + 1;  
          }  
          i++;  
          }     
  }  
  
  void countWords(string str) // Count The words 
  {
      int count = 0, i; 
  
      for (i = 0; str[i] != '\0';i++)
      {
          if (str[i] == ' ')
              count++;    
      }
   
      cout &lt;&lt; &quot;\n- Number of words in the string are: &quot; &lt;&lt; count +1 &lt;&lt;&quot; -&quot;;
  }
  
  //Sort the array in descending order by the number of words
  void sortByWordNumber(int num[30])
  {
     /* CODE str::sort? std::*/
  }
  
  int main()  
  {  
      string str = &quot;Program to split strings. By using custom split function. In C++&quot;;  
      char seperator = '.'; // dot  
      int numberOfWords;
      
      split(str, seperator);  
      cout &lt;&lt;&quot; The split string is: &quot;;  
      for (int i = 0; i &lt; max; i++)  
      {  
          cout &lt;&lt; &quot;\n initial array index: &quot; &lt;&lt; i &lt;&lt; &quot; &quot; &lt;&lt; strings[i];
          countWords(strings[i]);
          
      }  
      return 0;  
  }  
  
  </code></pre>
  <p>Count + 1 in countWords() is giving the numbers correctly only on the first result then it adds the &quot; &quot; whitespace to the word count.</p>
  <p>Please take into consideration answering with the easiest solution to understand first. (std::sort, making a new function, lambda)</p>