/**** * * This is the first example from Chapter 11 of the book. The only difference * is a small matter of style -- using the type name Planet instead of * planet_t. This is simply a matter of convention for naming types; it * doesn't change the meaning of the program at all. * */ #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; int main() { Planet p; /* variable of type Planet */ /* * 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; /* * Print values out, just for a quick test. */ printf( "\nPlanet name: %s\nDiameter: %.1f\nNumber of moons: %d\n\ Orbit time: %.1f\nRotation time: %.3f\n\n", p.name, p.diameter, p.moons, p.orbit_time, p.rotation_time); return 0; }