Re: (C) Simulated progress bar
From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 11/14/04
- Next message: Jonathan G Campbell: "Visual C++ 6.0 or 7.x for teaching in a games context?"
- Previous message: David White: "Re: timing code execution"
- In reply to: Paul Fedorenko: "(C) Simulated progress bar"
- Next in thread: Chris \( Val \): "Re: (C) Simulated progress bar"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 14 Nov 2004 12:31:41 +0100
Paul Fedorenko wrote:
> My friend, the psychologist, who asked me to put together a little
> program for him has asked me if I could get the program to pause for a
> second between turns and to display a progress indicator to make it
> look like the program's running some calculations in the background.
>
> I'm thinking the progress bar would be fairly straight-forward...
> Just a for loop, set up to display a bunch of hashmarks or ASCII block
> characters
> one at a time... How would I get it to take a second or two to run
> through
> the loop? That sounds like an awfully long time.
If you can use non-standard extension, then ask in a group for your OS
what call the OS provides to let your program wait for some time.
If you can only use standard C functions, you can write a busy-loop like
this:
#define WAITING_TIME 2 /* seconds */
time_t start = time(NULL);
for (double elapsed = difftime(start, time(NULL));
elapsed < WAITING_TIME;
elapsed = difftime(start, time(NULL)))
{
/* show progress bar (use elapsed to determine if a new segment can be
shown */
}
Bart v Ingen Schenau
-- a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
- Next message: Jonathan G Campbell: "Visual C++ 6.0 or 7.x for teaching in a games context?"
- Previous message: David White: "Re: timing code execution"
- In reply to: Paul Fedorenko: "(C) Simulated progress bar"
- Next in thread: Chris \( Val \): "Re: (C) Simulated progress bar"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|