print multiple variables as a single string

How to cascade and print multiple sensor values (variables) as a single string. I want to to read the output from two sensors and print them as a single string.

for eg if the output from the first sensor is AAA and the second sensor output is BBB I want print AAABBB as a single string. Is it possible to do so?

I use sprintf().


   char buf[20];
   sprintf(buf,"%d%d",a,b);  //format two ints into character array

float variables are by default not supported by sprintf() in Arduino.

You could also use several Serial.print() one after then other.


Indeed, if you want to just print it, just use multiple .print()'s. The other end sees no difference between

Serial.print"hello world");
Serial.print("hello ");

And it's way more efficient than sprintf(). That's a bit of a bazooka to kill a mosquito.