/* Compare to dbl.c. */ #include #include int chararray_append(char **a,int *aspace,int *alen,char c) { if (*alen == *aspace) { int yspace = *aspace * 2 + 1; char *y = (char *) realloc(*a,yspace); if (!y) return 0; *a = y; *aspace = yspace; } (*a)[*alen] = c; ++*alen; return 1; } int main(void) { char *x = 0; int xspace = 0; int xlen = 0; char c; int i; while (scanf("%c",&c) == 1) { if (!chararray_append(&x,&xspace,&xlen,c)) { printf("out of memory\n"); exit(1); } if (c == '\n') { for (i = 0;i < xlen;++i) putchar(x[i]); for (i = 0;i < xlen;++i) putchar(x[i]); xlen = 0; } } return 0; }