3
printf("\e[2J\e[0;0H");

What does this line mean?

Can I know what to learn and from where to understand this statement?

Mickael B.
  • 4,755
  • 4
  • 24
  • 48

2 Answers2

1

"\e" as an escape sequence is not part of the C standard.

A number of compilers treat the otherwise undefined behavior as a character with the value of 27 - the ASCII escape character.

Alternative well defined code:

//printf("\e[2J\e[0;0H");
printf("\x1B[2J\x1b[0;0H");
printf("\033[2J\033[0;0H");
#define ESC "\033"
printf(ESC "[2J" ESC "[0;0H");

The escape character introduces ANSI escape sequences as well answered in @Mickael B.. Select terminals implement some of these sequences.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
0

They are ANSI escape sequences

These sequences define functions that change display graphics, control cursor movement, and reassign keys.

It starts with \e[ and the following characters define what should happen.

2J: clears the terminal

Esc[2J Erase Display: Clears the screen and moves the cursor to the home position (line 0, column 0).

0;0H moves the cursor to the position (0, 0)

Esc[Line;ColumnH Cursor Position: Moves the cursor to the specified position (coordinates).

See also:

Mickael B.
  • 4,755
  • 4
  • 24
  • 48