Skip to content

Instantly share code, notes, and snippets.

View amullins83's full-sized avatar

Austin Mullins amullins83

  • Milsoft Utility Solutions
  • Abilene, TX
View GitHub Profile
@amullins83
amullins83 / README.md
Last active February 23, 2025 01:33
A simple command-line progress bar in C

#Progress in C

This is in an example meant to present some ideas regarding command-line progress bars in C.

##Important parts

The main idea is to overwrite stdout with new information every time a particular step is reached. I accomplished this using the VT100 emulator hack from [this Stack Overflow answer][1]. In a nutshell, printing ^[[2K to stdout erases the current line, but it doesn't necessarily move the cursor to the start. Printing \r does that. Also, I decided I wanted to print a newline character after the progress indicator, but I need to get rid of that newline on the next print. That's what \b does: it inserts a backspace, deleting the last character printed.

Also important is the call to fflush, which will guarantee that the print operation completes and is visible before the program moves on to its next task (see [this Stack Overflow answer][2]).

@amullins83
amullins83 / define-pure-virtual.cpp
Last active August 29, 2019 01:52
Define a Pure Virtual Method
#include <iostream>
using namespace std;
class Abstract
{
public:
virtual void DoStuff() = 0;
};