title: Creating a sequence of numbers from a string of digits C++
body: <p>I need to make a program where a user inputs a string of numbers.<br>
  It then outputs the numbers grouped so that each grouping, separated by a space, is larger than the last when you put the numbers together.<br>
  If the remaining digits together equal a sum smaller than the previous grouping they are omitted.<br>
  Ex.:<br>
  <code>314159265</code> would output <code>3 14 15 92</code><br>
  <em>Here:   3 &lt; 14  &lt;15 &lt; 92 but 65 was omitted because it is less than 92</em></p>
  
  <p>or<br>
  <code>9876543210</code> would output <code>9 87 654 3210</code><br>
  <em>Here: 9 &lt; 87 &lt; 654 &lt; 3210</em>  </p>
  
  <p>It has to do this 5 times with strings 1-20 characters long.   </p>
  
  <p>My code works for shorter strings, ie the ones above, but when they are longer than around 12 characters the end output messes up. </p>
  
  <p>Ex.:
  <code>98765432101234567898</code> outputs <code>9 87 654 3211 12333</code> instead of <code>9 81 654 3210 12345 67898</code>
  <em>Here: 9 &lt; 87 &lt; 654 &lt; 3211 &lt; 12333 it should output 9 &lt; 87 &lt; 654 &lt; 3210 &lt; 12345 &lt; 67898</em></p>
  
  <p>I have no idea why it doesn't work with larger strings and any help would be greatly appreciated.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;iomanip&gt;
  #include&lt;math.h&gt;
  #include&lt;string&gt;
  #include&lt;stdlib.h&gt;
  
  using namespace std;
  
  void input (string &amp;a,string num[20]){
      string numfinal,temp;
      cout&lt;&lt;"Enter the string of numbers: ";
      getline(cin, a);
      int length=a.length();
      for(int i=0;i&lt;length;i++){
          num[i]=a.substr(i,1);
      }
  
      for(int r=0;r&lt;length;r++){
          int n=atoi(temp.c_str());
          int o=atoi(num[r].c_str());
          int p=temp.length();
          if((length-r&lt;=p)&amp;&amp;(o&lt;n)){
          }
          else if((o&gt;n)||(r==0)){
              temp=num[r];
              numfinal=numfinal+temp+" ";
          }
          else if((o&lt;n)||(o=n)){
              int w=n;
              temp=num[r]+num[r+1];
              n=atoi(temp.c_str());
              if(n&lt;w){
                  int a=1;
                  int q=r+2;
                  while(n&lt;w){
                      temp=temp+num[q];
                      n=atoi(temp.c_str());
                      p++;
                      a++;
                  }
                  numfinal=numfinal+temp+" ";
                  r=r+a;
              }
              else{
                  numfinal=numfinal+temp+" ";
                  r++;
              }
          }
      }
      cout&lt;&lt;numfinal&lt;&lt;endl;
  }
  
  int main(){
      string a;
      string num[20];
      for(int r=0;r&lt;5;r++){
          input(a,num);
      }
      return 0;
  }
  </code></pre>