Structures:
struct tod{
int minute;
int hour;
};
struct event
{
int start, end;
};
Array:
int main (void)
{
struct event schedule[] = {{{9,45},{9,55}},{{13,0},
{14,20}},{{15,0},{16,30}}};
printf ("%d\n", freetime (schedule,3,8,0));
}
How come when i do schedule[0].end I get 9 and not 45? or schedule[1].end I get 13 instead of 55. How do I get the minute values in the array? Aren't the first set of 3 curly braces the start times? and the second set the end times? I don't know how to use the structures above to save these values.
Here is my code
int freetime (struct event schedule[], int n, int hour, int min)
{
struct tod time1;
struct tod time2;
int i;
int result = 1;
for (i=0; i<n; i++)
{
time1.hour = schedule[i].start;
time1.minute = schedule[i].end;
i++;
time2.hour = schedule[i].start;
time2.minute = schedule[i].end;
if(hour >= time1.hour && hour < time2.hour)
{
if(min >= time1.minute && min < time2.minute)
{
result = 0;
break;
}
}
}
return result;
}
freetime is supposed to return 1 if the specified time (hour and minute) is not part of any scheduled event; returns 0 otherwise. The value n specifies the size of the array containing the schedule.
{{{9,45},{9,55}},{{13,0},{14,20}},{{15,0},{16,30}}}represents a 2D array of typestruct event