显示进度指示器 [英] Show progress indicator

查看:72
本文介绍了显示进度指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linux 中使用 C.我如何显示一个进度指示器,让我知道程序(或程序的一部分)何时完成?例如,它可能类似于正在搜索...67%",并且百分比会一直增加,直到搜索部分结束.

I'm using C in Linux. How do I show a progress indicator that will let me know when the program (or parts of the program) will complete? For example, it could be something like "Searching...67%" and the percentage will keep increasing until the Searching portion ends.

谢谢.

推荐答案

我相信如果你这样做:

while (perc < 100) {
    printf("Searching... %d%%\r", perc); 
    fflush(stdout);
    //do work
}

fflush() 是避免行缓冲所必需的.请注意,我使用的是 \r 而不是 \n.

the fflush() is necessary to avoid the line buffering. Note that I am using \r and not \n.

这篇关于显示进度指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆