How would I print a spinning curser in a utility that runs in a terminal using standard C?
I\'m looking for something that prints: \\ | / - over and over in the same pos
You can also use \r:
#include
#include
void
advance_spinner() {
static char bars[] = { '/', '-', '\\', '|' };
static int nbars = sizeof(bars) / sizeof(char);
static int pos = 0;
printf("%c\r", bars[pos]);
fflush(stdout);
pos = (pos + 1) % nbars;
}
int
main() {
while (1) {
advance_spinner();
usleep(300);
}
return 0;
}