ac21
November 27, 2019, 5:43am
1
Is there something like strtol or strftime that will allow me to convert the two digit number in the arry to byte?
void checktime(){
time_t now;
time(&now);
char time_output[30];
char time_output2[30];
byte hour = strtol(time_output, 30, "%M", localtime(&now)); //hours
byte minute = strftime(time_output2, 30, "%I", localtime(&now)); //minutes
}
wvmarle
November 27, 2019, 12:43pm
2
Which two digit number in which array?
localTime returns a pointer to a struct tm, which has, among others, tm_hour and tm_min fields.
ac21
November 27, 2019, 5:04pm
4
wildbill:
localTime returns a pointer to a struct tm, which has, among others, tm_hour and tm_min fields.
You say that because there's two lines of code when I could do it with one?
What are you trying to achieve ?
Perhaps an explanation / worked example ?
Hutkikz
November 29, 2019, 2:33am
6
you'll need to iterate through the individual char's.
if ( isDigit(myChar[0])) // is this char a digit?
{
byte thisDigit = myChar[0] - '0'; // convert char to byte
byte num;
if (num == 0) // first digit
{
num = thisDigit;
}
else // add more digits
{
num = (num * 10 + thisDigit);
}
}