How to update a printed message in terminal without reprinting

后端 未结 8 2139
时光取名叫无心
时光取名叫无心 2020-11-29 02:50

I want to make a progress bar for my terminal application that would work something like:

 [XXXXXXX       ] 

which would give a visual indi

8条回答
  •  再見小時候
    2020-11-29 03:20

    Another option is to simply print one character at a time. Typically, stdout is line buffered, so you'll need to call fflush(stdout) --

    for(int i = 0; i < 50; ++i) {
       putchar('X'); fflush(stdout);
       /* do some stuff here */
    }
    putchar('\n');
    

    But this doesn't have the nice terminating "]" that indicates completion.

提交回复
热议问题