Timer in C - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Timer in C

diddididdi Posts: 1Member
Hi!

I would like to know how to create a timer or such in C (unix).
something like
"Enter password within 10 seconds: "
"Enter password within 9 seconds: "
"Enter password within 8 seconds: "

without having a new row each time ofcourse.
Or to create a progressbar "[======> ]" that will automatically update on the same place!

Anyone : )?

Thanks in advance!

/ Diddi

Comments

  • kevanwoodcockkevanwoodcock Posts: 172Member
    : Hi!
    :
    : I would like to know how to create a timer or such in C (unix).
    : something like
    : "Enter password within 10 seconds: "
    : "Enter password within 9 seconds: "
    : "Enter password within 8 seconds: "
    :
    : without having a new row each time ofcourse.
    : Or to create a progressbar "[======> ]" that will automatically update on the same place!
    :
    : Anyone : )?
    :
    : Thanks in advance!
    :
    : / Diddi
    :

    Hi
    There are timer functions, takea look at my code, it will point you in the rite direction. Sorry the code is a little messy, but i hope it helps.

    : [code]
    #include
    #include

    //used to calculate time durations.
    //this function sets global vars clock_t ticksstart, when called


    void Timing_start(void)
    {

    CHAR szBuf[200];
    clock_t ticks_start,


    // clock() returns type clock_t which is long double.
    ticks_start = clock();



    while((ticks2/CLOCKS_PER_SEC-ticks1/CLOCKS_PER_SEC)<1) //wait for 1 second
    {
    ticks2=clock();
    }



    sprintf(szBuf, "Took %ld ticks to wait one second.

    This value should be the same as CLOCKS_PER_SEC which is %ld.
    ", ticks2-ticks1, CLOCKS_PER_SEC);
    MessageBox(NULL, szBuf, "Timing fnt", MB_OK);


    // Or use the followign to print out.

    //printf("Took %ld ticks to wait one second.
    ",ticks2-ticks1);
    //printf("This value should be the same as CLOCKS_PER_SEC which is %ld.
    ",CLOCKS_PER_SEC);


    return;
    }
    : [/code]
Sign In or Register to comment.