user7828716 :
I need to extract numbers from my char array, it stores value in format hh:mm(example 20:20) I tried using sscanf function to extract hh into hour variable and mm to minute variable. It is working nicely until the time is something like 0number:0number or if it is 00:00 ..It only returns the number without the 0 or only one 0. Is it possible that when it reads the first 0 it takes it as something else ,not the part of the array value? Thank you for any answer.
char time[15]; ///where I store the time value
Serial.println(time); //prints nicely something like 02:02
int hour;
int minute;
sscanf(incas,"%02d:%02d",&hour,&minute);
Serial.println(hour); ///prints 2
Serial.println(minute); ///prints 2
Ted Lyngmo :
An int
has no clue about leading zeroes. 0000000000000123 == 123
. If you want leading zeroes, you'll have to format it yourself.
Example converting hour
and minute
back to a char
array:
char out[15];
sprintf(out, "%02d:%02d", hour, minute);
Serial.println(out);
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=390676&siteId=1