How to build a timer that counts the seconds elapsed?

This is a discussion on How to build a timer that counts the seconds elapsed? within the C Programming forums, part of the General Programming Boards category; I still don't get it how would I use that on the code I already have... I think I'll just ...

  1. #16
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    I still don't get it how would I use that on the code I already have... I think I'll just leave this function out of the final game and just check in the end how much time elapsed from the start of the game. Time is running out and I only have 2 days to finish it and a few critical bugs are still left in the code...

    Thanks for all your time though.

  2. #17
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You could pretty much just replace
    Code:
    ch = mvgetch(l, c);
    with something like
    Code:
    move(l, c);
    if(kbhit()) {
        ch = getch();
        /* process ch -- the if(ch...) code */
    }
    
    /* update the screen, including the timer */
    BTW, I wouldn't call a variable l (lowercase L). It looks too much like 1 (numerical one).

    Also, the variable i seems to play the same role as the variable c, unless they start at different numbers.

    As well, this
    Code:
    mvprintw(l, c, " ");
    is the same as
    Code:
    mvaddch(l, c, ' ');
    not that it matters too much. But it might be easier to read for this code, for instance:
    Code:
    mvprintw(l, c++, "%c", ch);
    ->
    Code:
    mvaddch(l, c++, ch);
    See the man page: http://developer.apple.com/documenta...vaddch.3x.html

    ----

    But work on the critical bugs first.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #18
    Registered User
    Join Date
    Mar 2006
    Posts
    158
    Thanks for all the suggestions but I won't do the timer anymore, I'm getting really confused and I only have a few hours left before the system blocks me from uploading my project. I have it all finished now, everything seems to be working and I'm just missing the final report, so, lots of writing to do and can't bother any more with the code... I did what I initially thought of doing, the game starts I check the time, the game ends I recheck the time and calculate the difference in seconds, that's it. Simple enough. No time for more.

    Thank you all though.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 06:29 PM
  2. calculate elapsed seconds
    By George2 in forum C# Programming
    Replies: 11
    Last Post: 04-21-2008, 02:18 AM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  4. Boom, Headoshot!!
    By mrafcho001 in forum A Brief History of Cprogramming.com
    Replies: 50
    Last Post: 07-21-2005, 09:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21