/* * George Brecht. "TWO EXERCISES," Fall 1961. * Arranged for terminal in C by David W. Speck, 2010. */ #include #include /* TWO EXERCISES */ /* Consider an object. */ typedef struct object { int part; struct object *object; } object; /* Call what is not the object "other." */ int other(int object) { if (object == EOF) return getchar(); else return putchar(object); } int main(void) { int another; object *new; object *object = NULL; /* * EXERCISE: Add to the object, from the "other," another * object, to form a new object and a new "other." * * Repeat until there is no more "other." */ while ((another = other(EOF)) != EOF) { if ((new = malloc(sizeof(struct object))) == NULL) return 1; new->part = another; new->object = object; object = new; } /* * EXERCISE: Take a part from the object and add it to the * "other," to form a new object and a new "other." * * Repeat until there is no more object. */ while (object != NULL) { if (other(object->part) == EOF) return 1; new = object->object; free(object); object = new; } return 0; }