typr

Typing practice program
git clone git://git.z3bra.org/typr.git
Log | Files | Refs

commit 82b278d63cf3e06ef4cedc97757238945fcc4b50
parent 5211c044e98da94d4eb1acacfe68854d27b25987
Author: Willy Goiffon <contact@z3bra.org>
Date:   Tue, 16 Mar 2021 17:31:30 +0100

Add comments about typing speed calculation

Diffstat:
Mtypr.c | 21++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/typr.c b/typr.c @@ -4,6 +4,22 @@ * * Type the text that is under the cursor. * The cursor will stop on errors, no need to backspace + * + * + * Typing speed can be calculated using the time(1) and wc(1) commands: + * + * $ time ./typr file.txt + * […] + * >> errors: 0 + * 0m28.64s real 0m00.00s user 0m00.00s system + * ^^^^^ TIMESPENT + * + * $ wc -w file.txt + * 28 file.txt + * ^^ WORDCOUNT + * + * WPM = (WORDCOUNT * 60) / TIMESPENT + * ( 28 * 60) / 28.64 = 58 WPM */ #include <stdio.h> @@ -57,6 +73,9 @@ main(int argc, char *argv[]) f = argc > 1 ? fopen(argv[1], "r") : stdin; + if (!f) + return -1; + tty = open(_PATH_TTY, O_RDWR); tcgetattr(tty, &term); @@ -77,7 +96,7 @@ main(int argc, char *argv[]) fclose(f); close(tty); - printf(">> errors: %d\n", tot); + fprintf(stderr, ">> errors: %d\n", tot); return 0; }