간단히 C언어에서 wget처럼 진행상태를 표시하고자 할 때 사용하면 적절하당


void DoProgress(char label[], int step, int total)

{

const int pwidth = 72;


int width = pwidth - strlen(label);

int pos = (step * width) / total;


int percent = (step * 100) / total;


printf("%s[", label);


for (int i = 0; i < pos; i++)  printf("%c", '=');


printf("% *c", width - pos + 1, ']');

printf(" %3d%%\r", percent);

}


사용법은


label 변수에 이 프로그레스바에 대한 정보를 써넣고..(위에선 Test이다.)

step 변수에는 총 토탈중에 현재 몇인지(토탈 127인데 현재 24이면 24)

total 변수는 토탈값을 넣으면 된다.

+ Recent posts