Typing Tutor Project

This is a discussion on Typing Tutor Project within the C Programming forums, part of the General Programming Boards category; I am doing this project on a typing tutor software. Done a few stuff already. But stuck with certain problems. ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    9

    Question Typing Tutor Project

    I am doing this project on a typing tutor software. Done a few stuff already. But stuck with certain problems. Would be very grateful if someone helped me out :-)

    Here goes my code:

    Code:
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    #include <dos.h>
    #include <time.h>
    
    void extview(int, int);
    
    void main(){
         FILE *fp;
         int i;
         int x=0;
         int y=0;
         int z=4;
         int errcnt=0;
         int cnt=0;
         int spcnt=0;
         float acc;
         time_t start=0, end=0;
         char str[650];
         char ch;
         clrscr();
    
         fp=fopen("C:\\test.txt","rt");
         fgets(str,650,fp);
    
         extview(z, i);
    
    /* Loop To Print The String */
    
         for(i=0;i<strlen(str);i++){
              gotoxy(10+(x++),5+y);
              printf("%c", str[i]);
              if ((i%50==0) && (i!=0)){
                   y+=3;
                   x=0;
              }
         }
    
         x=0;
         y=0;
         ch=0;
    
    /* Getting Input From The User & Highlighting Wrong Input */
    
         for(i=0;i<strlen(str) && ch!=27;i++){
              gotoxy(10+(x++), 6+y);
              ch=getch();
              if (start==0){
                   start=time(NULL);
                   }
              cnt++;
              textcolor(WHITE);
              if (ch!=str[i]){
                   textcolor(RED);
                   if (ch==32)     cprintf("%c", 24);
                   else cprintf("%c", ch);
                   sound(500);
                   delay(100);
                   nosound();
                   errcnt++;
                   }
              else
              printf("%c",ch);
              if((i%50==0) && (i!=0)){
                   y+=3;
                   x=0;
              }
         }
    
    /* Accuracy & WPM Calculation */
    
              end=time(NULL);
              cnt--;
              errcnt--;
              acc = (1.0*(cnt - errcnt) / cnt) * 100.0;
              gotoxy(64,8);
              printf("Accuracy: %.1f%", acc);
              gotoxy(64,14);
              printf("WPM: %.2f", (65/(difftime(end, start)/60)));
              gotoxy(64,18);
              printf("%d", spcnt);
    
         getch();
    }
    
    void extview(int z, int i){
         gotoxy(8,3);
         printf("%c", 218);
         for(i=0;i<53;i++){
              printf("%c", 196);
              }
         gotoxy(62,3);
         printf("%c", 191);
         gotoxy(8,4);
         for(i=0;i<40;i++){
              printf("%c", 179);
              gotoxy(8,z++);
              }
         z=4;
         for(i=0;i<40;i++){
              printf("%c", 179);
              gotoxy(62,z++);
              }
         gotoxy(8,43);
         printf("%c", 192);
         gotoxy(62,43);
         printf("%c", 217);
         z=4;
         gotoxy(9,43);
         for(i=0;i<53;i++){
              printf("%c", 196);
              }
         gotoxy(63,3);
         printf("%c", 218);
         gotoxy(63,4);
         z=4;
         for(i=0;i<40;i++){
              printf("%c", 179);
              gotoxy(63,z++);
              }
         gotoxy(63,43);
         printf("%c", 192);
         gotoxy(64,3);
         for(i=0;i<16;i++){
              printf("%c", 196);
              }
         gotoxy(80,3);
         printf("%c", 191);
         gotoxy(80,4);
         z=4;
         for(i=0;i<40;i++){
              printf("%c", 179);
              gotoxy(80, z++);
              }
         gotoxy(80,43);
         printf("%c", 217);
         gotoxy(64,43);
         for(i=0;i<16;i++){
              printf("%c", 196);
              }
    }
    What I wanna do here is that after the text file is opened the number of spaces in the whole string (650 characters in total and 65 words) will be calculated. But I have no idea how to do that.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know how to use a loop of any kind? Do you know how to increment a variable? Do you know how to test a character to see if it's a space? There ya go.


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

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thx for replyin :-) I know all that. But I can't do it. I tried using this:

    Code:
     
    
    while(1){
             ch=fgetc(fp);
             if (ch==" ") spcnt++; //spcnt is the count of spaces
    }
    That didn't work. Any other suggestions? :-)

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, if you had paid attention to your compiler's warnings, it would have told you what you were doing wrong. But, in the event you don't have them on:
    Code:
    if (ch==" ")
    This is a string. You can't compare strings with the == operator. You want to compare a single character.
    Code:
    if( ch == ' ' )
    Notice the single quotes. Single quotes, single character.

    A better way perhaps would be:
    Code:
    while( (c = fgetc( fp )) != EOF )
        if( c == ' ' )
            spcnt++;
    There are a number of ways to do this, but that's fairly simple, and it breaks out of the loop correctly when it hits the end of the file. Of course, 'c' needs to be int in this case to handle EOF. It's in the FAQ if you care for further explanation.


    [edit] void main is wrong, and is also covered in the FAQ. [/edit]

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

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thx for replying. I will definately try that out. So I need to declare c as an integer haa. I seen a lot of books using int main() some using only main() others using void main(). Dunno the difference. Where is the FAQ located? Am new here! :-)

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    This isn't working actually :S:S

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    There is a link to the FAQ at the top of the page, or else click here.
    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.

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thx :-)

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    fp=fopen("C:\\test.txt","rt");
    You should test to see if the open was successfull.
    Code:
    if((fp=fopen("C:\\test.txt", "rt")) == NULL) perror("Can't open file"), exit(1);
    And this
    Code:
        x=0;
         y=0;
         ch=0;
    Could be
    Code:
        x = y = ch = 0;
    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.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Also, I think your screen is probably 80x25, os 79 is the maximim column accessable, not 80:
    Code:
    gotoxy(80,43);
    And 43 . . . I don't know, maybe you're using a larger screen size.
    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.

  11. #11
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Thx for the advice. But gotoxy(80,43) actually works and my monitor is 15 inch!

  12. #12
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Awrite. Have been able to get it working. But minor glitches remain. I will be back wit em later! Thx all! :-)

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    The monitor screen doesn't have anything to do with it, it's the screen mode. But gotoxy() probably limits it's arguments to 80x25 with %.
    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.

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Code:
    void extview(int z, int i){
    It seems to me that you're using i in for loops . . . so just declare it locally.
    Code:
    void extview(void) {
        int z, i;
    And you're aware, of course, that 0 is a valid time?
    Code:
        time_t start=0, end=0;
    This
    Code:
         z=4;
         for(i=0;i<40;i++){
              printf("%c", 179);
              gotoxy(62,z++);
              }
    could be
    Code:
        for(i = 0; i < 40; i ++) {
            printf("%c", 179);
            gotoxy(62, i+4);
        }
    And, as you may have discovered in the FAQ, main() should be declared as
    Code:
    int main(void) {
    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.

  15. #15
    Registered User
    Join Date
    Jul 2005
    Posts
    9
    Well I learnt about the int main thingy from the faq. And time has been set to 0 so that the time keeping starts when the first key is pressed!

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

Similar Threads

  1. Speed in Touch Typing
    By stevesmithx in forum A Brief History of Cprogramming.com
    Replies: 60
    Last Post: 12-01-2008, 09:01 AM
  2. How to avoid typing std:: (scope resolution operator)
    By Sharan in forum C++ Programming
    Replies: 9
    Last Post: 04-30-2006, 08:25 PM
  3. Hide or Mask Typing
    By Jperensky in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 12:10 PM
  4. typing with no output
    By rkjd2 in forum C++ Programming
    Replies: 1
    Last Post: 03-16-2002, 03:12 PM

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