Andrey Bushman
Andrey Bushman

Reputation: 12486

Changing of existing text in console window

Sometimes, when I install programs, I see progress bar in console window (or other, dynamic changing text). It is displayed, and changing in the same row of string. When I use printf or other function, I write next text, but I can't modify in console window already existing text. How can I do it through C?

Upvotes: 1

Views: 225

Answers (2)

Eregrith
Eregrith

Reputation: 4366

If you want to keep using printf and have an easy go at "changing" the text, use \r which is carriage return on linux. It won't work on MAC though, because it means newline.

If you do this, I'd advise using ioctl to hide the caret to prevent flickering and an ugly effet.

If you want a better way of manipulating text on-screen you can have a look at ncurses

Upvotes: 2

Kos
Kos

Reputation: 72261

The easiest way for this kind of effects is to use the caret return \r character that lets you write over the previous line.


If you'd like to have direct access to the console's buffer (i.e. writing in specific X/Y position instead of line-by-line), then you're probably looking for a helper library like pdcurses.

Upvotes: 3

Related Questions