davidcallanan / os-series

803 stars 118 forks source link

void clear_row( size_t row ) and void print_char(char character) #73

Open GrooverMD opened 1 year ago

GrooverMD commented 1 year ago

VS Code would not accept this, but I thought I'll have a craic at it (Irish pun intended)

void clear_row(size_t row) {
struct Char empty = (struct Char) {
    character: ' ', ; error here "character is undefined"
    color: color,
    };

for (size_t col = 0; col < NUM_COLS; col++) {
    buffer[col + NUM_COLS * row] = empty;
    }
}

as a Pascal programmer I used the following construct

void clear_row( size_t row ) 
{
   struct Char empty = ( struct Char )
    {
        empty.character = ' ',
        empty.color = color,
    };

   for ( size_t col = 0; col < NUM_COLS; col++ ) 
    {
        buffer[col + NUM_COLS * row] = empty;
    }
}

and under print_char(char character)

void print_char(char character) 
    {
    if (character == '\n') {
        print_newline();
        return;
    }

    if (col > NUM_COLS) 
    {
        print_newline();
    }

buffer[col + NUM_COLS * row] = (struct Char) 
    {
        buffer[col + NUM_COLS * row].character = (uint8_t) character,
        buffer[col + NUM_COLS * row].color = color,
    };

    col++;
}

not sure if this is right but it works.