STRUCTURES WHICH CONTAIN STRUCTURES
Structures can also contain structures. Consider where both a
date and time structure are combined into a single structure
called date_time, eg,
struct date { int month, day, year; }; struct time { int hours, mins, secs; }; struct date_time { struct date sdate; struct time stime; };
This declares a structure whose elements consist of two other previously declared structures. Initialization could be done as follows,
static struct date_time today = { { 2, 11, 1985 }, { 3, 3,33 } };
which sets the sdate element of the structure today to the eleventh of February, 1985. The stime element of the structure is initialized to three hours, three minutes, thirty-three seconds. Each item within the structure can be referenced if desired, eg,
++today.stime.secs; if( today.stime.secs == 60 ) ++today.stime.mins;