Hi,
I receive from my RTC day, month and year.
I want to format those throughout my program in DD-MM-YYYY (so January should be "01" and not "1").
I thought of using sprintf, but I came to the conclusion that - even though the value gets assigned to a buffer - you lose that value immediately after another sprintf is used...
How to get the same result and allow the dateDDMMYYYY to be used throughout my program?
void updateTime() {
lcd.setCursor(0, 0);
//printf consumes more memory. Can also try even snprintf_P */
sprintf(dateDDMMYYYY, "%02d-%02d-%04d", RTC.getDay(), RTC.getMonth(), RTC.getYear());
//Serial.println(dateDDMMYYYY); --> Here it prints!
sprintf(timeHHMM, "%02d:%02d", RTC.getHours(), RTC.getMinutes()); //printf consumes more memory. Can also try even snprintf_P */
sprintf(timeHHMMSS, "%02d:%02d:%02d", RTC.getHours(), RTC.getMinutes(), RTC.getSeconds()); //printf consumes more memory. Can also try even snprintf_P */
Serial.println(dateDDMMYYYY); // --> Here it doesn't!
lcd.print(dateDDMMYYYY);
lcd.print("-");
lcd.print(timeHHMM);
}
Thank yo so much J-M-L!
I really didn't know about the extra character required at the end (and never included that).
Fixed all the buffers, and works like a charm now!
Thanks!!
(since I know the size for each, I went for the least memory consuming option).
I effectively tried that after your first remark, but got issues when reading (after writing) again from the SD card, while with regular printf it seemed to go fine.