Hi all,
I'm struggling a bit with this, not sure if it's the logic or code failing me!
What I want to do is set either a 1 or a 0 for each hour of each day of the week.
So ultimately I'll end up with:
day_0, hour_0 = 1
day_0, hour_1 = 1
day_0, hour_2 = 0
day_0, hour_3 = 0
And so on, so that I can then check the current hour and day, compare and decide if my lights (via relay) should be on or off.
I thought storing this in a struct should work well, so I've done this:
typedef struct _day {
char *hours[2];
} mydaystruct;
typedef struct _week {
mydaystruct days [7];
} myWeeksSchedule;
myWeeksSchedule days;
I can then reference this in code and read/write like this:
days.days[0].hours[0]
days.days[0].hours[1]
days.days[0].hours[2]
days.days[0].hours[3]
etc, but I think I've made an error as each time I write to them and read them back they always return 1.
I use myvar (set elsewhere) to then write the data into the array like this:
while(tmp_day < 7) {
tmp_hour=0;
while (tmp_hour< 24) {
if(myvar == "1") {
strncpy(days.days[tmp_day].hours[tmp_hour], "1",1);
} else {
strncpy(days.days[tmp_day].hours[tmp_hour], "0",1);
};
tmp_hour++;
};
tmp_day++;
};
Anyone spot what stupid mistake I've made on the struct/array?