C Timers

Discussion in 'Programming/Scripts' started by dualxeon, Feb 23, 2008.

  1. dualxeon

    dualxeon New Member

    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:

    Code:
    #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
     
  2. dualxeon

    dualxeon New Member

    problem solved
     
  3. falko

    falko Super Moderator Howtoforge Staff

    Do you mind to tell us how? ;)
     
  4. dualxeon

    dualxeon New Member

    sure,i used the C sleep function instead
     

Share This Page