[C] Loading Animation 05-25-2014, 08:10 PM
#1
A simple loader animation I wrote for Windows. 
[
edit: Wow, ugly ass, and poor, syntax highlighting... Not to mention slow.

[
Code:
cpp]#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
void print_progress(int percent)
{
const int mul = 2; // width factor
percent = min(100, percent);
// spinning animation
static int spin_index = 0;
char spinning[] = "_-\\|/-";
// bar filler
int len = (percent * mul / 10) + 1;
char *bar = malloc(len);
memset(bar, '<', len - 1);
bar[len - 1] = 0;
// write display
printf("%c Loading: [%*s] %*d%%\r",
percent == 100 ? ' ' : spinning[spin_index],
mul * 10, bar,
3, percent
);
spin_index = (spin_index + 1) % strlen(spinning);
free(bar);
}
int main()
{
printf("\nStarting Loader...\n");
for (int i = 10; i <= 100; i += 5)
{
print_progress(i);
Sleep(150);
}
printf("\nDone...\n");
}edit: Wow, ugly ass, and poor, syntax highlighting... Not to mention slow.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: 6s4zk0.jpg]](http://oi58.tinypic.com/6s4zk0.jpg)