printing two variables on the same line [solved]

hi guys
so Im working with a gps module. I want to write to a file two variables on the same line delimited by a coma. how can i achieve this? right now i have it so it writes latitude on one line and longitude on another. how can i combine the two variables in the println statement?

so this is wat i have -->>
lat
lon

this is wat i want -->
lat, lon

gps.f_get_position(&latitude, &longitude);
File dataFile = SD.open("Test.csv", FILE_WRITE);  
dataFile.println(latitude,5);
dataFile.println(longitude,5);
dataFile.close();

any help would be appreciated. thanks a bunch in advance.
cheers

SNK

Does this work?

dataFile.print(latitude,5);
dataFile.print(",");
dataFile.println(longitude,5);

don't use .println(), the ln means add a new line after printing. Use .print() until the last print when presumably you do want a new line.


Rob

thank you for a quick reply. yes, this works great. thank you very much. but just curious, is there a way to combine this in one statement?
cheers,

SNK

No, because "sprintf" doesn't support floats.
Is it all that important?

The printing routines are cut-down from standard C functionality
to fit on small microcontrollers, so no printf (which would link in all the various
print functions for every type).

You could define your own printf in terms of sprintf and print if you wanted it.

MarkT:
The printing routines are cut-down from standard C functionality
to fit on small microcontrollers, so no printf (which would link in all the various
print functions for every type).

You could define your own printf in terms of sprintf and print if you wanted it.

But "sprintf" doesn't support floats.

dataFile.println(latitude,5);

is there a way to combine this in one statement?

It depends on why you want to do it. If it is to tidy up the source code and perhaps make it more readable you could always put the statements in a function and call it with the values to be written as arguments.

Or you could put the statements on one line of typing.... of course that's the same coding but might simply look nicer.