dualxeon
23rd February 2008, 20:25
Hi,
I have written the following script in C to show the word bang every three seconds. However its not working correctly, heres the script:
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
int start_time;
int now;
start_time = time(&rawtime);
loop:
now = time(&rawtime);
if (now - start_time >3) {
printf ("BANG!!");
//start_time = now;
}
goto loop;
return 0;
}
At the moment, when I run this script after 3 seconds it constantly outputs bang though I only want this once per 3 seconds. To me it make sense if you uncomment the line
//start_time = now;
this should make output once every 3 seconds, but instead it doesnt at all,
Any help would be apreicated,
Thanks
I have written the following script in C to show the word bang every three seconds. However its not working correctly, heres the script:
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
int start_time;
int now;
start_time = time(&rawtime);
loop:
now = time(&rawtime);
if (now - start_time >3) {
printf ("BANG!!");
//start_time = now;
}
goto loop;
return 0;
}
At the moment, when I run this script after 3 seconds it constantly outputs bang though I only want this once per 3 seconds. To me it make sense if you uncomment the line
//start_time = now;
this should make output once every 3 seconds, but instead it doesnt at all,
Any help would be apreicated,
Thanks