title: Finding all Strings in an array
body: <p>I tried solving this all day but I cannot find an adequate solution.
  I want to print all words of an input char array, but if I type in an empty space at the start or at the end of the array my result is wrong.
  Does somebody know how to fix this or does somebody have an understandable solution for me? Thank you!
  Using a library would be okay to if it is understandable :)</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;cmath&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  const int len = 1000;
  char inputnames[len];
  int main()
  
  {
      int counter = 0, z = 0;
  
      cout &lt;&lt; &quot;Type in the Candidates names and press enter please: &quot;;
      cin.getline(inputnames, len);
  
      string stringstream(inputnames);
      string token;
  
  
      char LastCharacter = stringstream.back();
  
  
  
      if (LastCharacter == ' ') {
          counter = 0;
          for (int z = 0; z &lt; len; z++) {
              if (inputnames[z] &gt;= 'a' &amp;&amp; inputnames[z] &lt;= 'z' &amp;&amp; inputnames[z + 1] == ' ' || inputnames[z] &gt;= 'A' &amp;&amp; inputnames[z] &lt;= 'Z' &amp;&amp; inputnames[z] == ' ')
              {
                  counter++;
              }
              cout &lt;&lt; inputnames[z];
          }
      }
  
      else if (LastCharacter != ' ') {
          counter = 1;
          for (int z = 0; z &lt; len; z++) {
              if (inputnames[z] &gt;= 'a' &amp;&amp; inputnames[z] &lt;= 'z' &amp;&amp; inputnames[z + 1] == ' ' || inputnames[z] &gt;= 'A' &amp;&amp; inputnames[z] &lt;= 'Z' &amp;&amp; inputnames[z] == ' ')
              {
                  counter++;
              }
              cout &lt;&lt; inputnames[z];
          }
      }
  </code></pre>
  <p>[EDIT] Hello guys, I solved the last bug now, which involved +1 count if user typed in a space bar at the end of the input message. Please let me know if you have further tips/help/critic. Thank you all!</p>