r/C_Programming • u/Specialist-Cicada121 • 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!
7
u/Leonardo_Davinci78 Dec 23 '25
Thanks, I tested it without problems. I'll use it for tracking long tasks. Nice!
5
u/mjmvideos Dec 23 '25
The thing about progress bars is that they should reflect actual progress not just elapsed time and they also must not run autonomously. The thing I hate most is when an application hangs, but since the progress bar just runs in its own thread periodically updating the user thinks progress is still being made. Any progress bar I make must be “kicked” in order to register progress. If the app hangs, the bar is no longer updated. Then I add the progressBar.kick(increment) in loops and after significant processing steps in my code. Cuz I also hate when the percentage displayed doesn’t reflect the actual percent through the task leading to things like reaching 95% early and then staying there until the task actually completes some relatively large amount of time later.
3
u/kevkevverson Dec 23 '25
Looks nice! I would possibly lose the FOR macros, it seems odd to have the progress bar be the owner of the processing loop
2
u/Gozilu42 Dec 23 '25 edited Dec 24 '25
Why are you doing things like that:
followed by
? This is a really odd choice to use a temporary buffer, where the ".2f" could be done directly in the last string.
Also, be careful with your variable names "steps_per_ms" printed as "it/s"
sandmsare not the same, unit.2
u/inz__ Dec 24 '25
Nice work. Code is clean and consistent, very easy to follow.
Some points from read-through:
else ifsecond check is unnecessary, since already guaranteed by the loop conditionbararray anyway has an upper limit of about 1000 due to the result buffer's size of1024