Hello,
I was wondering if it was possible to set, for example, a 3 second delay between printf() statements?
Example:
Please enter your age: 35
>3 second delay<
Please enter your gender: M
>3 second delay<
You're a 35 year old male.
Hello,
I was wondering if it was possible to set, for example, a 3 second delay between printf() statements?
Example:
Please enter your age: 35
>3 second delay<
Please enter your gender: M
>3 second delay<
You're a 35 year old male.
Sure. Just use the 'clock' function to count off the time.
EDIT: Don't forget to normalize the results with CLK_TCK.
Last edited by Sebastiani; 03-23-2010 at 01:50 PM.
Thanks, I'll look into it.
Or you could use Sleep() or sleep() (depending on your system) so you don't have to burn so many cycles.
I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo
Why would you do that?
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
It's for a practical joke (under normal circumstances, I wouldn't imagine a reason for it either).
I think he was referring to NeonBlack's post, actually.
Anyway, once you have that function worked out, try this:
Code:void pause( clock_t val ) { /* ...the implementation... */ } clock_t next( ) { static int unset = 1; if( unset ) { --unset; srand( time( 0 ) ); } return ( ( clock_t )( rand( ) * 1000 * ( 1 / ( double )RAND_MAX ) ) ) >> 2; } void say( char const* str ) { while( *str ) { putchar( *str++ ); pause( next( ) ); } } int main( void ) { say( "I think, therefore I am." ); }
Right,
well, I found that the quickest and shortest way was to use NeonBlacks' method.
I added <windows.h> and beneath my statement, I put: Sleep(3000);