>>460 題意が分かりにくいが、こんなもんでいいのかな
#include <stdio.h>
#include <stdlib.h>
void push(char **s, int *nc, int *sz, int c)
{
    if (*nc == *sz) *s = realloc(*s, *sz *= 2);
    (*s)[(*nc)++] = c;
}
char *getline(FILE *fp)
{
    char *s = malloc(1);
    int c, nc = 0, sz = 1;
    while ((c = getc(fp)) != EOF && c != '\n')
        push(&s, &nc, &sz, c);
    if (nc == 0 && c == EOF) return 0;
    if (c == '\n') push(&s, &nc, &sz, '\n');
    push(&s, &nc, &sz, 0);
    return s;
}
int main(void)
{
    char *s, **lines = malloc(sizeof(char*));
    int nc = 0, sz = 1;
    while (s = getline(stdin)) {
        if (nc == sz) lines = realloc(lines, sizeof(char*)*(sz*=2));
        lines[nc++] = s;
    }
    while (nc) fputs(lines[--nc], stdout);
    return 0;
}