creating a timer in useing C lang.

Posted on 2007-07-29
Last Modified: 2011-09-20
I want to create a timer using C.  It would start by a decision such as if ( 1 -- 1) {start timer}.
It would be represented as mnutes and seconds,  10:00 down to 00:00 and then reset.
Question by:DanFlyBoy
    LVL 13

    Expert Comment

    A few questions:
    1)  Does this need to be portable?
    2)  If not, what operating system are you using?
    3)  What resolution do you need?  
    4)  Is this a simple example program or do you have other threads running?
    LVL 13

    Expert Comment

    If you are running Windows, then
    is a good reference.

    Author Comment

    The operating system is VXWorks, runnung on a power pc processor.  I am using c as the lanugauge.
    LVL 13

    Expert Comment

    I'm afraid someone else will need to help.  Sorry.

    Author Comment

    the code should be like a stopwatch, once decsion is made to start timer, it should count down like a stop watch froom 10:00 to 0.  Time will be displayed on screen.
    LVL 13

    Accepted Solution

    You may already know all about this...No offense intended.
    gives the VxWorks API, and one page titled "timerLib", which is
    describes a function which may do it for you.  That is "timerConnect", which lets you specify a function to be executed when the timer goes off.  You can use "timer_settime" to set the timer interval.

    You might do something like

    void myFunc(timer_t timerid, int arg) {
       /* update your stopwatch display */
      /* remember to set a flag when the stopwatch goes to zero */

    int timerNumber = 1;
    const struct itimerspec timerSpec = /* whatever is 1 second*/;
    int myTimer = timer_connect(timerNumber,myFunc,0)
    int result = timer_settime(myTimer,~TIMER_ABSTIME,&timerSpec,NULL);
    while (/*stopwatch hasn't gone zero) {
       /* do something */

    That's about the best I can do.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now