title: How do you parse a c-string?
body: <p>Hi I'm trying to take a c-string from a user, input it into a queue, parse the data with a single space depending on its contents, and output the kind of data it is (int, float, word NOT string).</p>
  
  <p>E.g. Bobby Joe is 12 in 3.5 months \n</p>
  
  <p>Word: Bobby</p>
  
  <p>Word: Joe</p>
  
  <p>Word: is</p>
  
  <p>Integer: 12</p>
  
  <p>Word: in</p>
  
  <p>Float: 3.5</p>
  
  <p>Word: months</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>int main()
  {
      const int maxSize = 100;
  
      char cstring[maxSize];
  
      std::cout &lt;&lt; "\nPlease enter a string: ";
      std::cin.getline(cstring, maxSize, '\n');
  
  //Keyboard Buffer Function
  buffer::keyboard_parser(cstring);
  
  return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>#include &lt;queue&gt;
  #include &lt;string&gt;
  #include &lt;cstring&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;vector&gt;
  
  namespace buffer
  {
      std::string keyboard_parser(char* input)
  {
      //Declare Queue
      std::queue&lt;std::string&gt; myQueue;
  
      //Declare String
      std::string str;
  
      //Declare iStringStream
      std::istringstream isstr(input);
  
      //While Loop to Read iStringStream to Queue
      while(isstr &gt;&gt; str)
      {
          //Push onto Queue
          myQueue.push(str);
  
          std::string foundDataType = " ";
  
          //Determine if Int, Float, or Word
          for(int index = 0; index &lt; str.length(); index++)
          {
              if(str[index] &gt;= '0' &amp;&amp; str[index] &lt;= '9')
              {
                  foundDataType = "Integer";
              }
              else if(str[index] &gt;= '0' &amp;&amp; str[index] &lt;= '9' || str[index] == '.')
              {
                  foundDataType = "Float";
                                      break;
              }
              else if(!(str[index] &gt;= '0' &amp;&amp; str[index] &lt;= '9'))
              {
                  foundDataType = "Word";
              }
          }
  
          std::cout &lt;&lt; "\n" &lt;&lt; foundDataType &lt;&lt; ": " &lt;&lt; myQueue.front();
          std::cout &lt;&lt; "\n";
  
          //Pop Off of Queue
          myQueue.pop();
          }
  }   
  }
  </code></pre>
  
  <p>Right now with this code, it doesn't hit the cout statement, it dumps the core.</p>
  
  <p>I've read about using the find member function and the substr member function, but I'm unsure of how exactly I need to implement it.</p>
  
  <p><strong>Note:</strong> This is homework.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>UPDATE:</strong> Okay everything seems to work! Fixed the float and integer issue with a break statement. Thanks to everyone for all the help!</p>