[C] change console output?

I noticed that linux is capable of "updating" the output from console, e.g. when it downloads something, there's a text progress bar, how do I do that in my program? e.g. I have this code

1
2
3
4
5
6
7
8
9
int main()
{
    printf("line 1\n");
    printf("line2\n");
    printf("line3\n");
    printf("line 4\n");    

    return 0;
}


how do I make it update line2 and line3 to "line 2" and "line 3" ?

or is there a way to clear the console output? another way than printing thousands of new lines
You may use '\r' to go back to the start of the line and print the updated version.
what if the output is multiline?
Then you need to use something like ncurses.
Topic archived. No new replies allowed.