If printf ("% c% c", "A", 8); removes A, why it is impossible to print f ("% c% c", '\ n', 8); delete new line? How should I do it?

How can I remove a new line character after printing in C code? I want to write a bunch of lines and delete them, and after a pause, print some other lines and then delete them ... in a loop. Like a real-time update without scrolling. I can print characters and delete them by printing the reverse character, but as soon as I print a new line, I cannot delete the created line. Is there any way to achieve this?

+4
source share
3 answers

The backspace character '\b' (ASCII 8) moves to the previous position within the line .

If you are under xterm or vt100 compatible, you can use console codes :

 #include <stdio.h> #include <unistd.h> /* for sleep() */ int main(void) { printf("Line\n"); sleep(2); printf("\033[A"); /* move cursor one line up */ printf("\033[K"); /* delete line */ return 0; } 

Alternatively, you can take a look at ncurses (Unix) or conio2 (Windows / MINGW)

+2
source

The backspace character does not "delete" anything. It is just a symbol, like everything else, in terms of the contents of bytestream / file. However, when printing to a terminal, backspace moves the cursor position one block to the left, allowing the next printable character to replace it on the screen. On most terminals, it does nothing if you are already in the leftmost position, but even if it works there, it does not know where to go to the previous line.

+1
source

0x08 or \b in ASCII is just a (special) character that is sent to stdout . How stdout handled is implementation dependent.

Link: Using \ b and \ r in C

0
source

Source: https://habr.com/ru/post/1499657/


All Articles