new to c++, with a weird error on runtime

Hi,  

I've just started to toy around with c++.  I wrote a program which takes a string and creates a text pyramid, using a random set of characters from the input.  Now, the thing compiles just fine and seems to run well under command prompt.  Except if my input is something which seems to be a  key word of somekind, i.e. "norbert test", the program goes nuts....printing funny characters for a while, if i type in "debug " ( space is needed to generate the error) then the program crashes, same with other string which seem like they might be system commands.

Here's the source code, which I cannot trace where I'd be getting this behavior from, any help would be appreciated.

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main(){
      try{
            cout<<"What phrase to pyramid?" <<endl;
            string phrase;
            getline(cin,phrase);
            const int strsize = phrase.size();
            string *pyramid = new string[strsize];
            string newmainstr;
            int nOfBlanks = 0;
            string *outbuf = new string[strsize];
            for(int linect = strsize-1;linect >= 0; linect--)
            {
                  newmainstr.append(nOfBlanks, ' ');
                  for(int pos = 0;pos <= linect; pos++)
                  {
                              newmainstr.append(1, phrase[rand()%strsize]);
                              newmainstr.append(1, ' ');
                  }      
                  nOfBlanks++;
                  outbuf[linect] = newmainstr;
                  newmainstr.clear();}
            for(int i = 0;i <= strsize;i++)
            {
                  cout << outbuf[i] <<endl;
            }
      }
      catch(string e)
      {
            cout << e << endl;
      }
      return 0;
      }
norbs101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
The problem is

          for(int i = 0;i <= strsize;i++)
         {
              cout << outbuf[i] <<endl;
         }

which should read

          for(int i = 0;i < strsize;i++)
         {
              cout << outbuf[i] <<endl;
         }

Using '<=', you are accessing an element that is not part of the array, thus the error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
norbs101Author Commented:
You are absolutely correct!!!  It's the same old oversight of a +/-  1 in a loop.  Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.