How can I erase the current printed console line in C? I am working on a Linux system. For example -
printf("hello");
printf("bye");
I want to print bye on the same line in place of hello.
How can I erase the current printed console line in C? I am working on a Linux system. For example -
printf("hello");
printf("bye");
I want to print bye on the same line in place of hello.
i
iterates through char array words.j
keeps track of word length."\b \b"
erases word while backing over line.Just found this old thread, looking for some kind of escape sequence to blank the actual line.
It's quite funny no one came to the idea (or I have missed it) that printf returns the number of characters written. So just print '\r' + as many blank characters as printf returned and you will exactly blank the previuosly written text.
As I cant use VT100, it seems I have to stick with that solution
You can use VT100 escape codes. Most terminals, including xterm, are VT100 aware. For erasing a line, this is
^[[2K
. In C this gives: