/* p22.c */ /* Managing lists of structures */ #include #include struct sphere_t { struct sphere_t *next; double center[3]; /* x, y, z */ double radius; }; struct sphere_t *head = NULL; struct sphere_t *tail = NULL; main() { double x, y, z; double r; struct sphere_t *new; while (scanf("%lf %lf %lf %lf", &x, &y, &z, &r) == 4) { new = malloc(sizeof(struct sphere_t)); new->center[0] = x; new->center[1] = y; new->center[2] = z; new->radius = r; new->next = NULL; if (head == NULL) { head = new; tail = new; } else { tail->next = new; tail = new; } } new = head; do { printf("Radius is %lf \n", new->radius); new = new->next; } while(new != NULL); }