int hour;
int minute;
int second;
char my_cstring [90];
void setup () {
Serial.begin (115200);
Serial.println("Setup-Start ");
Serial.println("enter a time in this format HH:MM:SS");
getHrMinSec ("10:15:32");
}
void getHrMinSec ( const char *time ) {
sscanf (time, "%d:%d:%d", &hour, &minute, &second);
// stat with well known pattern
Serial.print("hour=#");
Serial.print(hour);
Serial.print("# ");
Serial.print("minute=#");
Serial.print(minute);
Serial.print("# ");
Serial.print("second=#");
Serial.print(second);
Serial.print("#");
Serial.println();
// showing the generalised pattern of sprintf by expanding /varying the pattern
sprintf (my_cstring, "hour %d" ,hour);
Serial.println (my_cstring);
sprintf (my_cstring, "hour %d, minute %2d", hour, minute);
Serial.println (my_cstring);
sprintf (my_cstring, "hour %d, minute %2d, second %2d", hour, minute, second);
Serial.println (my_cstring);
}
void loop () {
if (Serial.available ()) {
char receivebuffer [90];
int n = Serial.readBytesUntil ('\n', receivebuffer, sizeof(receivebuffer)-1);
receivebuffer [n] = '\0'; // terminate with nul
getHrMinSec (receivebuffer);
}
}