-1

this is a part of my little 'C' program...

printf("Time to sleep for the end of process: %d sec\n", getpid() % 10);

I would like to come down the seconds, without the line on the terminal changes. Like an animation.

How can i do this in 'C'?

Thanks everyone!

0v3rl04d
  • 33
  • 1
  • 7

2 Answers2

2

Replace your \n with a \r, and as long as your numbers are all the same length (number of digits), I believe that should work.

qaphla
  • 4,707
  • 3
  • 20
  • 31
1

Try this; on Linux it should work. But don't print the '\n'; do a fflush(stdout); instead.

printf("%c[2K", 27);
printf("Time to sleep for the end of process: %d sec", getpid() % 10);
fflush(stdout);
Community
  • 1
  • 1
meaning-matters
  • 21,929
  • 10
  • 82
  • 142