Clearing output of a terminal program in Linux C

▼魔方 西西 提交于 2019-12-03 04:03:47
Naruil

There're several ways to delete the DDDDDDDDDDDDDD

  1. Print backspace several times
printf("\b");
  1. Print carriage-return and then print something to override the original line
printf("\r");
  1. If you are in a newline. You may use terminal commands to move your cursor

such as printf("\033[8;5Hhello"); // Move to (8, 5) and output hello

Other commands:

printf("\033[XA"); // Move up X lines;
printf("\033[XB"); // Move down X lines;
printf("\033[XC"); // Move right X column;
printf("\033[XD"); // Move left X column;
printf("\033[2J"); // Clear screen
...
  1. Don't forget ncurses

It is the best ways to control the exact layout and format in a terminal

If you are using X-Term compatibles (Gnome Terminal included), then print the following

printf("\033[2J");

or

cout << "\033[2J";

where \033 is the escape character in ASCII and [2J is the specific action (clear).

kandelvijaya

I tried answering for what is best expected here.

printf("AAAAAAAAAAAAAA");
printf("BBBBBBBBBBBBBB");
printf("CCCCCCCCCCCCCC");
//printf("DDDDDDDDDDDDDD");

comment the last line or delete if you dont want to display in terminal. printf("xxxx") is the statement used for printing output in terminal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!