If it works, then it's more by luck than judgement.
Your array is allocated on the stack. The stack is used to store parameters, local variables, return addresses etc, and every time you call a new function there is a good chance that your array contents will be overwritten.
Making this:
into this:
is marginally better in that it won't get overwritten by calling new functions, but it means that you lose the old value every time you call the function again.
Making the function either write to an array area that has been passed as a parameter, or passing back an object containing the string is a much better and safer way of doing it.
#include "DarkGDK.h";
#include <stdio.h>;
#include <string>;
#include <stdlib.h>;
#include <sstream>;
#include <iostream>;
#include "math.h";
//#define leftprec(x,y) (x - (((int)floor(x) - (((int)floor(x))% ((int)(pow(10,y)))))))
using namespace std;
float leftprec(float x,float y);
char* toString(float num);
void DarkGDK ( void ){
int PDist=1;
float power;
char *MyChar;
while (PDist>0.0f)
{
MyChar=dbInput();
PDist=atoi(MyChar);
power = (PDist/((float)sqrt((float)PDist)*(11.231f+(dbRND(2)))));//*500.00);//*(500.00+rnd(200)))
//power=(100/(dbSQRT(100)*(500)));
//*MyChar sendto toString(power);
dbPrint( (char*)(toString(power).c_str()) );
}
}
// returns the string representation of a number
string toString(float num) {
ostringstream myStream;
myStream<<leftprec(num,1)<<endl;
return myStream.str();
}
float leftprec(float x,float y)
{
return(x - (((int)floor(x) - (((int)floor(x))% ((int)(pow(10,y)))))));
}
When are TCG gonna make these darned functions accept
const char *