how to use println to out multiple variables

hello everyone, maybe a very easy question for you. I want to output multiple variables through println function, how can I do this?

for example, if I want to output variables a, b, c, how can I output them using println in one sentence? Thanks a lot, I am looking forward to your reply.

char buffer [40];
sprintf (buffer, "%d %d %d", a, b, c);
Serial.println (buffer);

One is to use a buffer: form the buffer and then print the buffer;

Another would be to print out them one at a time:

  Serial.print("A = "); Serial.print(a); Serial.print(". B = "); Serial.print(b); ...

Or you can do it via a function call - all fits your "one-line" requirement.

thanks for reply, but what will be output is float variables not char variables. And in arduino, is "sprintf" valid? thanks a lot.

"sprintf" is valid, but its use with "float" type is limited, though it can be patched.
Can I ask why it is so important that you output everything in a single expression?

And in arduino, is "sprintf" valid?

Yes, if you fiddle with the linker switches.

Otherwise, you can print its components:

  Serial.printf((int) f); //print a floater's integer portion
  Serial.printf('.'); //print a decimal point
  Serial.printf(abs(f * 100) % 100); //print the floater's two decimal point

You can change it to print out as many decimal points as you wish. Or to make a generic function out of it.

Serial.printf((int) f); //print a floater's integer portion
  Serial.printf('.'); //print a decimal point
  Serial.printf(abs(f * 100) % 100); //print the floater's two decimal point

Or, more succinctly and correctly Serial.println(f, 2);

@dhenry, please try not to mislead quite so much and occasionally RTFM

The reason I want to output it at one line is to be the input for the host computer. It is the form demand.

I still don't see why multiple "Serial.print"s wouldn't do the trick.

for example, in my program, there are four float variables outputs, float a, b, c, d. I want the outputs at one line which are all with 2 bits after the decimal points, how should I do? thanks a lot!

You know that the four float variables will be the input for the host computer, and the host computer has to read the serial port, every read it should read 4 variables at a time.

Serial.print (a, 2);
Serial.print (" ");
...
Serial.println(d, 2);

Of course, it may be a bit shorter if the values are in an array

xianpeng:
The reason I want to output it at one line is to be the input for the host computer. It is the form demand.

No I think you totally misunderstand what the format is saying. The host needs the four values and then a line feed / carriage return. It doesn't care, or even know, if this happened through three Serial.print statements and one Serial.println rather than just one print statement.