Tuesday, October 19, 2010

Typing Tutor in C

Coding is Fun. Don't believe me? Try the below program and verify yourself...


Pre-Requisites:

We need to measure time in order to calculate speed. This can be achieved by an inbuilt library "time.h". It has a datatype clock_t which is able to store absolute time. Thus using two clock_t variables: start and end, time interval(end - start) can be claculated. But this interval is number of CPU cycles and not time in seconds. Hence simply dividing it by number of clock cycles per second (2.3 GHz or whatever) will give time in seconds.clock() function is used to store values in start and end variables.



The Real Thing:

The core of program lies in user entering an input and calculating time user takes to enter that input. Thus pseudo code would be:

start = clock();
scanf("%s",input);
end = clock();

Further strcmp() function of "string.h" can be used to check whether user has entered proper input.


Thus I can think of two modes
  • Speed is main constraint. User has to enter sequence of characters as fast as possible. (Go for all time favorite a-z) 
  • Accuracy is the main constraint. Display an awkward string (Your teachers name) which user must enter exactly the same. 


So, turn on the PC and get going. I am finishing with some luring screenshots to make it more appealing.





Does'nt feel like stretching fingers? Grab the program HERE and start typing !!

4 comments:

  1. I am laughing by seeing your things.. You are a engineering student and you are using 20 year old software for coding. update your self, also the program you wrote is not engineering level. It look like a 12 class boy solving a+b=3 and a=2 then what is the value of b? type of question. Try http://www.codeblocks.org/ OR Learn QT or GTK.. People will really laugh at you if post such blog..

    ReplyDelete
  2. I think you are not getting the message out of post. The very first line says "Coding is Fun" and thats what you missed.

    1)Its not about developing a complete nice GUI typing tutor. its about what can you do even with 20 year old language.

    2)C is popular and common.

    3)This isn't about "Engineering Level". I wanted the program to be simple because the post is targeted to Non-engineering people, who think of programming as boring. If you want to have a look @ engineering level head http://bit.ly/ep0cW7 OR http://bit.ly/hZbzt1
    4) QT/GTK are languages I guess 99% of my blog audience never heard about. I would love to see how one can explain "Coding is fun" using them.

    Thanks for stopping by.

    ReplyDelete
  3. you can do same terminal coding in GCC too..
    what you doing is inspiring other to have fun using TC.. If you put instruction to use GCC and have same fun with GCC then people will think, Oh its new, Let me try,,, If you know good think then you must tell other - -- What you have done in "unintentional viral marketing"... Think like using .doc promote and tell other also to use same microsoft product and other will not be able to use think about openOffice..

    ReplyDelete
  4. As you pointed out in the comment I wanted the readers to respond in "Oh its new, Let me try" way and thats why I choose C.

    GCC has a major disadvantage that its not available for windows and even if I made it available no is going to install unknown software just to run this code. Kills "Let me try".

    The popularity and feeling of "nothing is harmful" in C helps in building "Lets go for it" attitude.

    And regarding publicizing good things, I am as much of FOSS activist as you are. I have already started posting series of "Imagine Linux and You" articles aimed at introducing and encouraging Linux.

    ReplyDelete