Last active
December 6, 2015 22:09
-
-
Save akoskovacs/89bfdc1da8abb97f5b81 to your computer and use it in GitHub Desktop.
Console progress bar example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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