Hi,
I am trying to convert the string from ctime to a struct but i always get garbage values if i use "uint8_t". But i can get correct values if i use "int" datatype. I want to do it using uint8_t as it will save some space, as the numbers wont be above 255 anyway. Do i need unable some flags in the gcc Makefile?
UINT8_T:
struct time_struct {
char wday[4];
char month[4];
uint8_t month_num;
uint8_t mday;
uint8_t mil_hour;
uint8_t hour;
uint8_t min;
uint8_t sec;
int year;
};
struct time_struct now;
time_t epoch = 1548617880;
sscanf(ctime(&epoch),"%s %s %d %d:%d:%d %d",now->wday, now->month, &now->mday, &now->mil_hour, &now->min, &now->sec, &now->year);
NRF_LOG_INFO("%s %s %hhd",now->wday, now->month, now->mday);
NRF_LOG_INFO("%d:%d:%d %d", now->mil_hour, now->min, now->sec, now->year);
NRF_LOG_FLUSH();
//Output:
/*
<info> app: Sun Jan 27
<info> app: 19:38:6 2019
*/
INT:
struct time_struct {
char wday[4];
char month[4];
uint8_t month_num;
int mday;
int mil_hour;
uint8_t hour;
int min;
int sec;
int year;
};
struct time_struct now;
sscanf(ctime(&epoch),"%s %s %hhd %hhd:%hhd:%hhd %d",now->wday, now->month, &now->mday, &now->mil_hour, &now->min, &now->sec, &now->year);
NRF_LOG_INFO("%s %s %hhd",now->wday, now->month, now->mday);
NRF_LOG_INFO("%hhd:%hhd:%hhd %d", now->mil_hour, now->min, now->sec, now->year);
NRF_LOG_FLUSH();
// Output:
/*
<info> app: Sun Jan 27
<info> app: 0:65:34 19059
* /
thanks.