#include #include #define BUFFER_SIZE 512 struct item { char data[BUFFER_SIZE]; struct item *next; }; void tac() { int eol = 0; struct item *first = malloc(sizeof(struct item)); struct item *last = first; first->next = NULL; while (1) { char *p; if (!fgets(last->data, BUFFER_SIZE, stdin)) { last->data[0] = 0; break; } for (p = last->data; *p; p++); eol = (p > last->data) && p[-1] == '\n'; if (eol) { break; } else { struct item *next = malloc(sizeof(struct item)); next->next = NULL; last->next = next; last = next; } } if (eol) tac(); while (first) { struct item *curr = first; first = first->next; fputs(curr->data, stdout); free(curr); } } int main() { tac(); return EXIT_SUCCESS; }