/**** * * This is the example from Page 568 of the book. It illustrates an array of * structs. * */ #include #include #define STRSIZ 10 typedef struct { char name[STRSIZ]; /* name of the planet */ double diameter; /* equatorial diameter in km */ int moons; /* number of moons */ double orbit_time; /* years to orbit sun once */ double rotation_time; /* hours to complete one revolution on axis */ } Planet; typedef struct { double diameter; /* diameter of system in km */ Planet planets[9]; /* array of planets */ char galaxy[STRSIZ]; /* name of the system */ } SolarSystem; int main() { Planet p; /* variable of type Planet */ SolarSystem ss; /* variable of type SolarSystem */ /* * Assign values to the components of p. */ strcpy(p.name, "Jupiter"); p.diameter = 142800.0; p.moons = 16; p.orbit_time = 11.9; p.rotation_time = 9.925; /* * Assign values to the components of ss. */ ss.diameter = 2.874E9; ss.planets[4] = p; strcpy(ss.galaxy, "Milky Way"); /* * Print values out, just for a quick test. */ printf( "\nFifth Planet name: %s\nDiameter: %.1f\nNumber of moons: %d\n\ Orbit time: %.1f\nRotation time: %.3f\n\n", ss.planets[4].name, ss.planets[4].diameter, ss.planets[4].moons, ss.planets[4].orbit_time, ss.planets[4].rotation_time); return 0; }