I'm trying to use this code to get temperature and humidity values from DHT11 sensor and send it to Python and I need to write the temperature and humidity values in the same line. But I keep getting the error code

expected primary-expression before '%' token

How can I fix this?

#include <dht.h>
#include <stdio.h>
int a = 0;
int b = 0;
char buffer [64];

dht DHT;

#define DHT11_PIN 7

void setup(){

void loop(){
  a = DHT.temperature;
  b = DHT.humidity;
  int chk = DHT.read11(DHT11_PIN);
  sprintf(buffer, %d %d, a, b);
  • 1
    The error mentioned a line number. Did you look at that line?
    – timemage
    Jan 24, 2021 at 0:39

1 Answer 1


You are missing quotes on the second parameter of sprintf:

sprintf(buffer, "%d %d", a, b);
  • please don't answer syntax error questions. they are off-topic
    – Juraj
    Jan 24, 2021 at 7:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.