/* The first version of this program had a bug: it used realloc(x,...) where it should have used realloc(x,...*sizeof(int)). */ #include #include int main(void) { int *x = 0; int xspace = 0; int xlen = 0; int n; while (scanf("%d",&n) == 1) { if (xlen == xspace) if (!(x = realloc(x,(xspace = xspace * 2 + 1) * sizeof(int)))) { fprintf(stderr,"out of memory\n"); return 111; } x[xlen++] = n; } for (n = 0;n < xlen;++n) if (x[n] < 0) printf("%d\n",x[n]); for (n = 0;n < xlen;++n) if (x[n] > 0) printf("%d\n",x[n]); return 0; }