#include <stdio.h>
#include <stdlib.h>int main()
{
int i;
int nu = 0;
int temp = 0;
int *p = NULL;
int *q = NULL; while(1)
{
if(scanf("%d", &temp) != 1)
{
return -1;
}
if(temp == -1)
{
break;
}
nu++; q = p; p = (int *)malloc(sizeof(int)*nu);
if(NULL == p)
{
return -2;
}
for(i = 0; i < nu - 1; i++)
{
p[i] = q[i];
}
p[i] = temp; if(q != NULL)
free(q);
} for(i = 0; i < nu; i++)
{
printf("%d ", p[i]);
}
printf("\n");
free(p);
p = q = NULL;
return 0;
}
// the realloc dynamic one dimensional array#include <stdio.h>
#include <stdlib.h>int main()
{
int i;
int nu = 0;
int temp = 0;
int *p = NULL; while(1)
{
if(scanf("%d", &temp) != 1)
{
return -1;
}
if(temp == -1)
{
break;
}
nu++; p = (int *)realloc(p,sizeof(int)*nu);
if(NULL == p)
{
return -2;
}
p[nu - 1] = temp;
} for(i = 0; i < nu; i++)
{
printf("%d ", p[i]);
}
printf("\n");
free(p);
p = NULL;
return 0;
}