How to remove row of empty line on terminal caused by "\x1b[2J" in C?
01:35 03 Oct 2026

I just learned how to create a simple code editor, but I've run into a problem, when I press Ctrl+Q, which is the key combination to exit the editor, it leaves row of empty lines, like this:

Ellan@ellan:~/Projects$ ./main.out
//(row of empty lines filling the screen)
Ellan@ellan:~/Projects$

This is most likely caused by this part of my code:

void editorRefreshScreen() {
    write(STDOUT_FILENO, "\x1b[2J", 4);     // clear the screen
    write(STDOUT_FILENO, "\x1b[H", 3);      // move the cursor to the top-left corner
}

How do I remove those empty line rows?, And is this empty line caused by the way I'm clearing the screen, or is there actually an extra step needed to get rid of that empty line gap?

c