#include #define TERM_WIDTH 80 void draw_progress(FILE *fp, unsigned long pos, unsigned long max) { unsigned long head, i; if (pos > max) pos = max; head = (TERM_WIDTH - 2) * pos / max; fputc('[', fp); for (i = 0; i < head; ++i) fputc('#', fp); for (; i < (TERM_WIDTH - 2); ++i) fputc(' ', fp); fputc(']', fp); for (i = 0; i < TERM_WIDTH; ++i) fputc('\b', fp); }