-
Busy animation?
Hi,
I've written a program which takes a while to complete what it has to do, going through a loop several billion times (You'd think it'd be speedy on a P4, but nooooooooo... :rolleyes: ), and I've tried adding a "busy" animation so I know it hasn't crashed. The way I tried to do it was:-
Code:
char chBusy[4] = { 0x2F, 0x2D, 0x5C, 0x7C }; // "/", "-", "\", "|"
int iBusyIndex = 0;
(inside loop)
putchar(0x08); // backspace to remove previous character
putchar(chBusy[iBusyIndex++]);
if (iBusyIndex = 4)
iBusyIndex = 0;
else
iBusyIndex++;
However, this doesn't produce the desired effect. I can't actually see the animation (perhaps it changes too quickly?) and the cursor hops back and forth like mad. What's the proper way, please? :D
-
An example, courtesy of Prelude:
Code:
#include <stdio.h>
#include <time.h>
void sleep ( long milli )
{
clock_t end, current = clock();
for( end = current + milli; current < end; current = clock() );
}
int main ( void )
{
int x = 0;
const char *barRotate = "|\\-/";
printf ( "Loading configuration files... " );
for ( ; ; ) {
if ( x > 3 ) x = 0;
printf ( "%c\b", barRotate[x++] );
sleep ( 200 );
}
return 0;
}
You probably won't want the sleep in your program, I only include it here to show you a complete working example.
-
Whoops, looks like I don't know all the printf flags, that's a much better way of doing it, thanx :)
-
here..
Code:
void showwhirl()
{
int i, j;
char whirl[] = {'|','/','-','\\\'};
for (i=0;i<=2; i++)
{
for (j=0; j<=3; j++)
{
printf("%c", whirl[j]);
delay(25);
printf("\b");
}
}
}