void read3(void) { int size = 50; // size of the array int next_index = 0; // where the next number goes int *numbers = malloc(size * sizeof(int)); while (has_next()) { if (next_index == size) { size *= 2; numbers = realloc(numbers, size*sizeof(int)); if (numbers == NULL) abort(); // error } numbers[next_index] = read_nat(); next_index++; } }
/* read_token: Read an S-expression token */ struct token read_token() { struct token t; skip_whitespace(); int c = getc(input); if( c == EOF ) { t.tag = TEOF; } else if( c == '(' ) { t.tag = LPAR; } else if( c == ')' ) { t.tag = RPAR; } else if( isgraph(c) && !isdigit(c) ) { t.tag = STR; t.str = read_id(c); debug("Read string: %s", t.str); } else if( isdigit(c) ) { t.tag = INT; t.num = read_nat(c); debug("Read string: %d", t.num); } else { printf( "bad character: %c\n", c ); abort(); } return t; }