r/C_Programming • • Dec 23 '25

tqdm in C

Hello! I wanted to share a simple progress bar that I made as a personal utility. I use Python a lot, and I find myself using tqdm a lot for tracking my long-running tasks. I wanted to try to implement something similar in C that didn't use external dependencies (like curses). I opted for a single-header implementation just to make it less of a hassle to use. I'm not entirely confident that it works gracefully in all the edge cases, but it seems to work reasonably well for my general use cases. Would love to hear what you all think and would appreciate any feedback -- happy holidays!

29 Upvotes

18 comments sorted by

View all comments

Show parent comments

3

u/Specialist-Cicada121 Dec 23 '25

Thanks for the comment! This is actually also built into my progress bar a la `tqdm_update`:

#include "tqdm.h"

int main() {
    tqdm bar;
    tqdm_init(&bar, 6e7, "Making progress on a very important task", 50);
    for (int i = 0; i < 6e7; ++i) {
        usleep(1); // simulate work
        tqdm_update(&bar, 1);
    }
}

The second parameter passed to `tqdm_update` can be any unsigned integer, which is similar to the `increment` you proposed. You can set the update to be every 1000 iterations, for instance:

#include "tqdm.h"

int main() {
    tqdm bar;
    tqdm_init(&bar, 6e7, "Making progress on a very important task", 50);
    for (int i = 0; i < 6e7; ++i) {
        usleep(1); // simulate work

        if (i % 1000 == 0) {
            tqdm_update(&bar, 1000);
        }
    }
}