Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GrooverMD opened this issue Sep 1, 2022 · 0 comments
Open

Comments

@GrooverMD
Copy link

GrooverMD commented Sep 1, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant