0% found this document useful (0 votes)
29 views4 pages

Typing Speed Test Program in C

Typing Speed tester

Uploaded by

Shlok Agarwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

Typing Speed Test Program in C

Typing Speed tester

Uploaded by

Shlok Agarwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include <stdio.

h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

#include <conio.h>

#define MAX_INPUT_LENGTH 1024

char *TARGET_TEXT = "Because of the laboriousness of the translation


process, since the 1940s efforts have been made, with varying degrees of
success, to automate translation or to mechanically aid the human
translator. More recently, the rise of the Internet has fostered a world-wide
market for translation services and has facilitated 'language localization'.
Ideally, the translator must know both languages, as well as the subject
that is to be translated.";

//character-level mistakes

int count_character_errors(char *originalText, char *typedText)

int originalLength = strlen(originalText);

int typedLength = strlen(typedText);

int minimumLength = (originalLength < typedLength)

? originalLength

: typedLength;

int errorCount = 0;

int i;

for (i = 0; i < minimumLength; i++) {

if (originalText[i] != typedText[i]) {
errorCount++;

errorCount += abs(originalLength - typedLength);

return errorCount;

void main()

clrscr();

printf("=== Typing Speed Tester ===\n");

printf("Type the following sentence and press ENTER:\n");

printf("\"%s\"\n\n", TARGET_TEXT);

printf("Press ENTER to start...");

getchar();

printf("\nStart typing:\n> ");

// start timing

clock_t startTime = clock();

char userTypedText[MAX_INPUT_LENGTH];

fgets(userTypedText, sizeof(userTypedText), stdin);

// stop timing

clock_t endTime = clock();


//new line removal

int len = strlen(userTypedText);

if (len > 0 && userTypedText[len - 1] == '\n') {

userTypedText[len - 1] = '\0';

// total time taken

double timeTakenSeconds = (double)(endTime - startTime) /


CLOCKS_PER_SEC;

double timeTakenMinutes = timeTakenSeconds / 60.0;

int totalCharactersTyped = strlen(userTypedText);

double wordsPerMinute = (timeTakenMinutes > 0)

? ((totalCharactersTyped / 5.0) / timeTakenMinutes)

: 0.0;

int totalErrors = count_character_errors(TARGET_TEXT, userTypedText);

int comparisonLength = (strlen(TARGET_TEXT) > strlen(userTypedText))

? strlen(TARGET_TEXT)

: strlen(userTypedText);

double errorPercentage = (comparisonLength > 0)

? (100.0 * totalErrors / comparisonLength)

: 0.0;

printf("\n--- RESULTS ---\n");

printf("Target text : \"%s\"\n", TARGET_TEXT);


printf("Typed text : \"%s\"\n", userTypedText);

printf("Time taken : %.2f seconds\n", timeTakenSeconds);

printf("Speed : %.2f WPM\n", wordsPerMinute);

printf("Errors : %d / %d (%.2f%%)\n",

totalErrors, comparisonLength, errorPercentage);

getch();

You might also like