Sensor values reading worng

I am only receiving the correct temperature value. The other 3 values are reading wrong. My format string isent matching the variable list. Can anyone tell me what I need to do.

float data_bar = 0.0;
float data = 0.0;
float anVal = 0.0;
float moistureVal = 0.0;
while(1)
{

// Get the new value using the get() function

data_bar = get(baro,BMP085_TEMP);
data = get(baro,BMP085_PRES);
anVal = get(light_sensor);
moistureVal = get(moisture_sensor);

// Preparing the messages to text

//define buffer for error messages
char tempError[20] = "";
char lightError[20] = "";

if(data_bar < 20)
{
//tempError = "turn up heat";
strcpy(tempError,"TURN ON HEAT!");
}

if(data_bar > 30 )
{
//lightError = "turn up heat";
strcpy(tempError,"TURN ON COOLER!");
}
if(anVal < 100)
{
//tempError = "turn up heat";
strcpy(lightError,"TURN ON LIGHTS!");
}
if(!readError())
{

sprintf(smsTextBuff,"Temperature: %f\r\nPressure: %f\r\nLight Value: %3.2f %s\r\nMoisture Value: %f %d\r\n",
(double)data_bar,tempError,(double)data,(double)anVal,lightError,(double)moistureVal);



UARTWrite(1, "Sending SMS...");
(double)data_bar,tempError,(double)data,(double)anVal,lightError,(double)moistureVal);

There are no format specifiers for the error strings. What's the last %d good for?
That is a mistake should be %f I think. So should I have %s after the temp and light values
Well, the number and type of format specifiers need to match exactly the provided parameter (like data_bar,tempError, etc) otherwise you'll risk a crash because sprintf cannot tell what and how many parameter it gets
Topic archived. No new replies allowed.