Hi.. I'm making a function to extract the decimals from a float.. and it works well when I print from inside the function, but when I use return() it shows weird characters..
void setup()
{
Serial.begin(115200);
}
void loop()
{
retorna_decimais(112.78);
}
char* retorna_decimais(float vfloat)
{
char vbuffer_float[7];
char valor_decimal[2];
float vvalor_subtraido = (vfloat - (int)vfloat);
dtostrf(vvalor_subtraido, 2, 2, vbuffer_float);
sprintf(valor_decimal, "%c%c", vbuffer_float[2], vbuffer_float[3]);
Serial.println(valor_decimal);
}
this prints the results correctly!!!
but.. when I use return() and try to use the value returned it shows weird characters..
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.println(retorna_decimais(112.78));
}
char* retorna_decimais(float vfloat)
{
char vbuffer_float[7];
char valor_decimal[2];
float vvalor_subtraido = (vfloat - (int)vfloat);
dtostrf(vvalor_subtraido, 2, 2, vbuffer_float);
sprintf(valor_decimal, "%c%c", vbuffer_float[2], vbuffer_float[3]);
//Serial.println(valor_decimal);
return(valor_decimal);
}
this returns...
a??
a??
a??
a??
a??
a
a
a
Am I passing the values to the function wrongly?
Could anyone help me?
Tks a lot
a
a