I found this code somewhere on the net...
But i dunno how to stop this...Its keeps animating and i dont know when will this stop...

#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;
}

>Its keeps animating and i dont know when will this stop...
Answer: Theoretically this won't ever stop, because there's an infinite loop in your main() function:

for ( ; ; ) {
  if ( x > 3 ) x = 0;
  printf ( "%c\b", barRotate[x++] );
  sleep ( 200 );
}

A for-loop defined as such: for ( ; ; ) { } means: 'for ever'. But if you want, you can always add a terminating condition between the two semicolons if you want the loop code to stop executing at some point.

I put ...

for ( ;x<10; ) {
  if ( x > 3 ) x = 0;
  printf ( "%c\b", barRotate[x++] );
  sleep ( 200 );
}

But still it wont stop..

if ( x > 3 ) x = 0; When will x ever actually reach 10?

if ( x > 3 ) x = 0; When will x ever actually reach 10?

thank you for your help i got it...

for ( ;x<5 ; ) 
                                               {
                                                    printf ( "%c\b", barRotate[x++] );
                                                    sleep ( 200 );
                                               }

----

It's not going to reach 5 either. The best way to do it would be to flesh out the for loop with the proper conditions (so say i=0;i<10;i++ ) and make the number of times it goes it independent of x. Either that or turn it into a while loop which breaks on some condition.

commented: Yes, that would indeed be a better idea :) +8

That's what i did actually hehe...
I dun know why i didnt put

(x=0;x<5;x++)

on my post above...

Use something other than x because that's already changing in your loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.