Home > Software design >  How to undo a " " in c?
How to undo a " " in c?

Time:12-19

So Imagine that I am printingf something in the x=0 and y = 0 coordinates and now I want to printf something in the coordinate x=-1 and y = 0. How can I do it? Imagine that I printf " " and now I what to undo that " ", how can I do it?

CodePudding user response:

Plain ISO C offers only very limited functionality of moving the text cursor on the screen. See the other answer for details on what it does offer.

However, most common operating systems provide their own additional functions that allow you to freely move the text cursor on the screen. For example, on Linux, you can use ncurses. On Micrsoft Windows, you can use the Console API, for example the function SetConsoleCursorPosition.

Also, some operating systems support ANSI escape codes that allow cursor positioning. For example, recent versions of Microsoft Windows support Console Virtual Terminal Sequences.

CodePudding user response:

If you have printed a partial line, so the active position on the display device is not at the beginning of a line, then printing the backspace character, '\b', is intended to move the active position to the previous position on the current line, per C 2018 5.2.2 2.

Historically, this was not supported on all devices, but, assuming you have not resurrected a half-century old teletype, your display device will likely support this.

The C standard’s specifications of display manipulation are very limited. The behavior of '\b' when the active position is at the start of the line is unspecified, and nothing is provided to move the position to previous lines or to arbitrarily chosen locations in the display or to erase characters.

  •  Tags:  
  • c
  • Related