Run-Time Check Failure #2 - Stack around the variable.
Dec 5, 2010 at 12:23pm UTC
I keep getting this error. "Run-Time Check Failure #2 - Stack around the variable 'temperatureArray' was corrupted." But i have another one programmed nearly like that one, however that one works.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
float Temperature::readValue(void )
{
if (onOff == 1)
{
char temperatureArray[]="" ;
timerPtr->start(500);
while (!timerPtr->checkForTimeout());
comTemperaturePtr->send("T" ,1);
while (comTemperaturePtr->inWatingBuffer() < 1);
comTemperaturePtr->receive(temperatureArray);
currentTemperature = (float )atof(temperatureArray);
}
else
cout << "Error" ;
return (currentTemperature);
}
The one that works:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
char sendDataArray[]="P\r\n" ;
bool status;
float puls;
status = serialobj.open(5, 38400);
while (1)
{
if (status)
{
char pulsDataArray[]="" ;
timerobj.start(500);
while (!timerobj.checkForTimeout());
serialobj.send(sendDataArray, strlen(sendDataArray));
while (serialobj.inWatingBuffer() < 1);
serialobj.receive(pulsDataArray);
puls = (float )atof(pulsDataArray);
cout << puls;
}
else
{
cout << "puls port ikke " << "\x86" << "ben" ;
}
Last edited on Dec 5, 2010 at 12:26pm UTC
Dec 5, 2010 at 12:32pm UTC
Both versions are incorrect. char pulsDataArray[]="" ;
creates a char array with just one element.
It is equivalent to char pulsDataArray[1]={'\0' };
Topic archived. No new replies allowed.