这个动态进度条打印的代码怎么写呀?
说要用到for循环。第一层循环从0~100。
每一个百分比中都打印100个字符。第二层循环打印的长度是总长度的百分比。
#include <stdio.h>
#include <windows.h>
#define PROGRESS_LEN 100//每一个百分比中都打印100个字符
void show_progress(int progress)
{
int i = 0;
int progress_finsh = 0;
progress_finsh = progress * PROGRESS_LEN / 100;//当前占总的百分比,例如20%
printf("\rProgress : |");
for (i = 0; i < PROGRESS_LEN; i++)
{
if (i < progress_finsh)//打印20个#
{
printf("%c", '#');
}
else
{
printf("%c", '-');//打印80个-
}
}
printf("| %d %%", progress);
}
int main(int argc, char *argv[])
{
int i = 0;
for (i = 0; i <= 100; i++)
{
Sleep(100);
show_progress(i);//1%到100%
}
return 0;
}