Text on lcd1602 using sprintf outputs wrong

Hello,
i have defined the following :

#include <stdio.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <virtuabotixRTC.h>
virtuabotixRTC myRTC(6, 7, 8);
char tTime[8] ;

in the loop i have the following :
lcd.setCursor(0, 1);
sprintf(tTime, "%2d:%2d:%2d", myRTC.hours, myRTC.minutes, myRTC.seconds);
Serial.write (tTime) ;
lcd.printf(tTime);

on the serial output, everything is correct
on the lcd the time is printed correct, but just after the time, strange characters are printed.

any idea how to solve this using formatted output ?

Thx
Frederik

tTime is too short for 8 characters, needs at least one additional space for the terminator character. Most likely the serial display is ignoring unprintable characters, while the LCD is treating them as special characters.

Serial.write is for one character. Serial.print is for a string.

marco_c:
Serial.write is for one character. Serial.print is for a string.

write() in the Print class is overloaded. If passed a char * it assumes a c string.

--- bill