Skip to content

Instantly share code, notes, and snippets.

@akoskovacs
Last active December 6, 2015 22:09
Show Gist options
  • Save akoskovacs/89bfdc1da8abb97f5b81 to your computer and use it in GitHub Desktop.
Save akoskovacs/89bfdc1da8abb97f5b81 to your computer and use it in GitHub Desktop.
Console progress bar example
#include <stdio.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
int i, j;
for (i = 0; i <= 100; i++) {
fprintf(stderr, "\rLoading [");
for (j = 0; j < 100; j++) {
fprintf(stderr, "%c", (i > j) ? '=' : '-');
}
fprintf(stderr, "]\t %3d%% ", i);
/* Doing stuff */
if (i % 4 == 0)
usleep(10000);
else if (i % 5 == 0)
usleep(90000);
else
usleep(40000);
/* End of stuff */
}
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment