How to make a progress bar using C program with percentage?
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100000
#define WIDTH 100
void main()
{
long i;
float p = 0.0;
int c = 0, x=0, last_c=0;
fprintf(stderr, "%3d%% [", (int)p);
for (x = 0; x < c; x++){
fprintf(stderr, "=");
}
for (x = c; x < WIDTH; x++){
fprintf(stderr, " ");
}
fprintf(stderr, "]");
for(i = 1; i < MAX+1; i++){
p = i*100.0/MAX;
c = (int) p;
fprintf(stderr, "\n\033[F");
fprintf(stderr, "%3d%%", (int)p);
fprintf(stderr, "\033[1C");
fprintf(stderr, "\033[%dC=", last_c);
for (x = last_c; x < c; x++){
fprintf(stderr, "=");
}
if(x<WIDTH){ fprintf(stderr, ">");
}
last_c = c;
}
fprintf(stderr, "\033[EDone\n");
}