0

If I printed say 10 lines in the console, then if we want to modify the second line(or move the cursor to the second line), how to do this in C? Is there any escape sequence for that, or any method to move cursor to desired coordinates?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • 5
    The C language itself has no knowledge of consoles or terminals. POSIX does know about terminals, but it does not define specific escape sequences for terminal control, and in fact there have historically been a rather large number of terminal types with distinct control code sets. If you want a text-based interface that supports moving the cursor around the screen, then you should look into the various external libraries that support it. One of the most widely used is (n)curses. – John Bollinger Jun 25 '18 at 14:01
  • Chances are that this works: `Esc` `[` row_number `;` column_number `H`. (Numbers are plain ascii representation). As stated in the comment above, it could not work... – linuxfan says Reinstate Monica Jun 25 '18 at 14:11
  • which OS are you using.? – anoopknr Jun 25 '18 at 16:16
  • @anoopknr zorin(ubuntu 16.04 LTS) – Suraj Patni Jun 25 '18 at 17:01
  • Possible duplicate of [Move the cursor in a C program](https://stackoverflow.com/questions/33025599/move-the-cursor-in-a-c-program) – Thomas Dickey Jun 25 '18 at 23:40

1 Answers1

0

You can use the ANSI escape sequences to manipulate the screen (including the cursor position)

ANSI-Escape-Sequences lists many of the ANSI escape sequences.

this page is a wiki article on the same subject

user3629249
  • 16,402
  • 1
  • 16
  • 17