/* Linked lists: sections 12.8 through 12.12. Try 3 1 4 1 5. */ #include #include struct intlist { int data; struct intlist *next; } ; int main(void) { struct intlist head = { 0, 0 }; struct intlist *t; int n; while (scanf("%d",&n) == 1) { t = (struct intlist *) malloc(sizeof(struct intlist)); if (!t) { fprintf(stderr,"fatal: out of memory\n"); exit(1); } t->data = n; t->next = head.next; head.next = t; } for (t = head.next;t;t = t->next) printf("%d\n",t->data); exit(0); }