/* An example of structures */
#include <stdio.h>
#include <string.h>
//the planet type
typedef struct planet
{
char name [10];
double diameter;
int moons;
double orbit, rotation;
} planet;
//the solar systems structure type contains a planet type component
typedef struct solarsystem
{
double diameter;
planet planets[8];
char galaxy [10];
} solarsystem;
int
main(void) {
planet p = {"Earth", 12742, 1, 1.0, 24.0};
solarsystem ss;
//variable p contains the entry of Earth
printf ("The planet %s has %d moon(s).\n", p.name, p.moons);
//copying Earth into cell #2 of the array of planets of variable ss
ss.planets[2] = p;
//putting Jupiter into variable p
strncpy (p.name, "Jupiter", 10);
p.diameter = 139822;
p.moons = 16;
p.orbit = 11.9;
p.rotation = 9.925;
printf ("Planet %s has %d moon(s).\n", p.name, p.moons);
printf ("Planet %s has %d moon(s).\n", ss.planets[2].name, ss.planets[2].moons);
return(0);
}