sps.c
State addRow(Table *table) {
    // allocate one more row pointer in the array
    Cell **p = realloc(table->cells, (table->rows + 1) * sizeof(Cell *));
    if (p)
        table->cells = p;
    else
        return ERR_MEMORY;

    // allocate new cell array for the new row
    table->cells[table->rows] = malloc(table->cols * sizeof(Cell));
    if (table->cells[table->rows] == NULL)
        return ERR_MEMORY;

    // initialize all the cells in the new row
    for (unsigned i=0; i < table->cols; i++) {
        cell_ctor(&table->cells[table->rows][i]);
    }
    table->rows++;
    return SUCCESS;
}
// adds an empty row to the end of the table
adds an empty row to the end of the table
adds an empty row to the end of the table
State addRow(Table *table) {
    Cell **p = realloc(table->cells, (table->rows + 1) * sizeof(Cell *));
    if (p)
        table->cells = p;
    else
        return ERR_MEMORY;
    table->cells[table->rows] = malloc(table->cols * sizeof(Cell));
    if (table->cells[table->rows] == NULL)
        return ERR_MEMORY;
    for (unsigned i=0; i < table->cols; i++) {
        cell_ctor(&table->cells[table->rows][i]);
    }
    table->rows++;
    return SUCCESS;
}
State addRow ( Table * table ) { Cell * * p = realloc ( table -> cells , ( table -> rows + 1 ) * sizeof ( Cell * ) ) ; if ( p ) table -> cells = p ; else return ERR_MEMORY ; table -> cells [ table -> rows ] = malloc ( table -> cols * sizeof ( Cell ) ) ; if ( table -> cells [ table -> rows ] == NULL ) return ERR_MEMORY ; for ( unsigned i = 0 ; i < table -> cols ; i ++ ) { cell_ctor ( & table -> cells [ table -> rows ] [ i ] ) ; } table -> rows ++ ; return SUCCESS ; }
adds an empty row to the end of the table
adds an empty row to the end of the table
// allocate one more row pointer in the array // allocate new cell array for the new row // initialize all the cells in the new row