Thread: Resetting Clock()???

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Resetting Clock()???

    Ok, i have my code:

    Code:
    int seconds;
    	clock_t clock();
    	seconds = clock()/CLOCKS_PER_SEC;
     
    	if (seconds == 8){
    			FIVE.SetPositionX(-1);
    			}
    //....
    if ((AdventureGame.keypressed[DIK_F]) && (WOO.positionX == -10)){
     
    		//reset clock() here
    		FIVE.SetPositionX(-5);
    }
    the clock starts when the program is run and after 8 secs, FIVE moves position.
    When i press F, i want FIVE to reset its position [which it does], and to reset the clock(), so that after 8 secs, FIVE will move again.
    Anyway to do this?
    Using Windows 7, visual studio

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You can't reset the clock(), so you should use another variable to save the old value, then compare that to the latest.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 06:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. using clock()
    By sl4nted in forum C Programming
    Replies: 8
    Last Post: 11-09-2006, 07:16 PM