Code:
const oofloat & oofloat::operator += (const oofloat & str)
{
oofloat copystring(str); // copy to avoid aliasing problems
oofloat size = (atof(CString) + str.converttofloat());
size = size.length();
int newLength = size.converttofloat(); // size of totaled number
int lastLocation = length(); // index of '\0'
// check to see if local buffer not big enough
if (newLength >= Capacity)
{
Capacity = newLength + 1;
char * newBuffer = new char[Capacity];
strcpy(newBuffer,CString); // copy into new buffer
delete [] CString; // delete old string
CString = newBuffer;
}
// now add str (copystring) to the integer value of CString
//itoa( (atof(CString) + copystring.converttofloat()), CString, 10 );
sprintf ( CString, "%f", (atof(CString) + copystring.converttofloat()) );
return *this;
}
At this line: //itoa( (atof(CString) + copystring.converttofloat()), CString, 10 );
That is what I was doing when I was doing a class similar to this, only with an integer. Now, I can't use "ftoa" because it doesn't exist, and the other functions I could find don't do what I want. However, another code sample someone gave me (used in my integer class) used sprintf. I tried to use it in
sprintf ( CString, "%f", (atof(CString) + copystring.converttofloat
()) );
so that I could store the double as a string. That works, but it gives me a memory violation. And on the other parts of the program; I have code like this:
Code:
const oofloat & oofloat::operator += ( double rhs )
{
double hold = atof(CString) + rhs;
char s[10];
sprintf ( s, "%f", hold );
return operator= ( s );
}
I need a replacement for sprintf there, too.
Thank you for the help!