Skip to content

Instantly share code, notes, and snippets.

@sgkim126
Last active March 21, 2023 12:53
Show Gist options
  • Save sgkim126/c5699b1b1094478d6f3bb8d297401b63 to your computer and use it in GitHub Desktop.
Save sgkim126/c5699b1b1094478d6f3bb8d297401b63 to your computer and use it in GitHub Desktop.
void display_progress_bar(int progress) {
static const int PROGRESS_BAR_LENGTH = 20;
int filled = progress * PROGRESS_BAR_LENGTH / 100;
fprintf(stderr, "\r[");
for (int i = 0; i < filled; i += 1) {
fprintf(stderr, "#");
}
for (int i = filled; i < PROGRESS_BAR_LENGTH; i += 1) {
fprintf(stderr, " ");
}
fprintf(stderr, "] %3d% %", progress);
if (filled == PROGRESS_BAR_LENGTH) {
fprintf(stderr, "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment