How to write to textfile to the same line not next one ?

Hi !

I use RTC to get time and date and want it to be written to SD card to textfile (or table). So the time and date should be in one line. The next time and date - on the next line. And so on.

Serial monitor writes it in one line, when the code is this:

Serial.print(clock.hour, DEC); Serial.print(":"); Serial.print(clock.minute, DEC); Serial.print(":"); Serial.print(clock.second, DEC); Serial.print(" "); Serial.print(clock.month, DEC); Serial.print("/"); Serial.print(clock.dayOfMonth, DEC); Serial.print("/"); Serial.print(clock.year+2000, DEC); Serial.print(" "); Serial.print(clock.dayOfMonth);

BUT when i try to write it into TEXTFILE - it becomes each number in next line... This is not cool .. Heres this part of code:

if (myFile) { Serial.print("Writing to test.txt..."); myFile.println(clock.second, DEC); myFile.println(clock.minute, DEC); myFile.println(clock.hour, DEC); myFile.println(clock.dayOfMonth, DEC); // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); }

\\\\\\\\\ i tried to write this: myFile.println(clock.second, clock.minute, clock.hour DEC); - it doesn't work at all ...

Please help !

thankyou !

Compare this:

Serial.print(clock.hour, DEC);

to this:

myFile.println(clock.hour, DEC);

println() adds a newline at the end of the string, print() doesn't.

When posting your code please enclose it in code tags.

Serial monitor writes it in one line, when the code is this:

That cannot be true as there is no println() in your code.

it becomes each number in next line...

That is definitely true as you have a println() for every line.

thanks, people.

i’ll try “print” instead of “println” - i’m new to the arduino code.