All pastes #1444854 Raw Edit

Anonymous

public c v1 · immutable
#1444854 ·published 2009-06-02 13:40 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#define INIT_SIZE 10#define ADD_SIZE 5int main(void){  int *a;  int size;  int n;  int i;  int temp;  size = INIT_SIZE;  a = (int *)malloc(size * sizeof(int));  n = 0;  while (1) {    printf("[%d] = ", n);    scanf("%d", &temp);    if (temp == -1) {      break;    }    a[n] = temp;    if ((n + 1) == size) {      printf("expand!\n");      size += ADD_SIZE;      a = (int *)realloc(a, size * sizeof(int));    }    n++;  }  for (i = 0; i < n; i++) {    printf("[%d] = %d\n", i, a[i]);  }  free(a);  return 0;}