Thread: random characters

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    4

    random characters

    hello, i need to make a program that generates a random character.
    after that the user have to type the same character on the keyboard
    the objective of the program is to calculate the reaction time of the user, i mean, calculate the time spend by the user between the creation of the random character and the input of the user.

    i can generate the random character, type that character on the keyboard and see if it«s the same or not but i have no idea how to calculate the reaction time

    if somebody can help me

    thanks, rebok

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why don't you know how to calculate it? (Didn't you already post this thread? Or was that someone else, because I swear I just read this post some place.)
    Code:
    nowtime = now
    display character
    read character from user
    reaction time = now
    elapse time = difference between nowtime and reaction time
    It's not hard if you take a bit of time to think about what's actually happening.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Using standard C functions, the reaction time won't be noticible if the user types fast. But it's possible to use clocks()/CLOCKS_PER_SECOND to find the reaction time down to the second. All that's necessary is to calculate the time before the input is entered and time after. Subtracting the two, dividing by CLOCKS_PER_SECOND, should then give you the reaction time.

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by okinrus
    (...)But it's possible to use clocks()/CLOCKS_PER_SECOND to find the reaction time down to the second.
    Not clocks() but clock()
    Not CLOCKS_PER_SECOND but CLOCKS_PER_SEC

    You may use this to get milliseconds:
    Code:
    clock()*1000/CLOCKS_PER_SEC/1000.0
    And #include <time.h>
    Last edited by xErath; 11-16-2004 at 10:19 PM.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Try a google search for "X C timing functions" where X is your operating system.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Thanks, xerath. You can't get milliseconds granulity in a standard, portable way, however.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. problem with reading characters
    By csvraju in forum C Programming
    Replies: 4
    Last Post: 03-31-2009, 07:59 AM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. Random word problem
    By goron350 in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2005, 03:44 PM
  5. Question for Random class
    By joenching in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2005, 11:22 PM