Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
10/11/2011 3:19:13 AM EDT


//Function creates an array of stars for positive temps
string Pos_Stars(int &temp)
{
int n = 0;
int j = 0;
char * p;
string posString = " ";
p = new char[n];
for(int i = 120; i > 3; i––)
{
if(temp == i)
{
n = temp / 3;
for(j = 0; n > j; j++)
{
p[j] = '*';
}
string posString(p, j);
}
}
delete[] p;
return posString;
}

EDIT:



Trying to convert the array to a string and return it. I am getting a memory corruption error after temp value of 30 is passed.
 
10/11/2011 3:35:58 AM EDT
[#1]
It's been a while, but you're only allocating 0 bytes on the heap (p = new char[n]) as you have n set to 0.

If you attempt to write anywhere in p (ie p[j] = '*') you'll get an access violation.

That being said, I'm not sure I fully understand what you're shooting for here.