英語タイピング練習ソフトをプログラミングで
Posted: 2017年1月26日(木) 17:31
用いているのはC言語です
問題
英語タイピング練習ソフトを作りたい.以下のような例文を入力した時の、入力にかかった時間を計測し,一分間に何文字入力できる早さであるかを出力するプログラムを作成せよ.入力ミスした際はもう一度行わせる.1分間に入力した文字数と時間を表示すること.
下記の英文は、char *words[5]のようなポインタ配列の初期値として与えるか、別途ファイルに書いておき、そこから読み込むようにする.
エラーは無いです
今は文章が一致しないため『A bad workman quarrels with his tools.』のみを定義しています
英文
↓
A bad workman quarrels with his tools.
Every man is the architect of his own fortune.
People who live in glass houses should not throw stones.
A bird in the hand is worth two in the bush.
As you make your bed, so you must lie in it.
プログラム
↓
/* -*-coding: utf-8-*- */
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char n[5][50];
/*char *words[] = {"A bad workman quarrels with his tools.",
"Every man is the architect of his own fortune.",
"People who live in glass houses should not throw stones.",
"A bird in the hand is worth two in the bush.",
"As you make your bed, so you must lie in it."};*/
int i, len;
time_t start, end;
char words[50] = "A bad workman quarrels with his tools.";
srand(time(NULL));
start = time(NULL);
for(i = 0; i < 5; i++){
printf("words%d?", i);
fgets(n, 500, stdin);
len = strlen(n);
/*len += len;*/
printf("%s\n", words);
printf("%d\n", len - 2);
/*printf("%d\n", strcmp(n, words));*/
if(strcmp(n, words) == 0){
puts("nとwordsの文字列は一致しています。");
}
else{
puts("nとwordsの文字列は一致していません。");
}
}
end = time(NULL);
for(i = 0; i < 5; i++)
printf("%s\n", n);
printf("一分に%d文字打ちました:%.0f秒かかりました", len, difftime(end, start));
return 0;
}
実行結果
↓
./a.out
words0?A bad workman quarrels with his tools.
A bad workman quarrels with his tools.
37
nとwordsの文字列は一致していません。
words1?Every man is the architect of his own fortune.
A bad workman quarrels with his tools.
45
nとwordsの文字列は一致していません。
words2?People who live in glass houses should not throw stones.
A bad workman quarrels with his tools.
55
nとwordsの文字列は一致していません。
words3?A bird in the hand is worth two in the bush.
A bad workman quarrels with his tools.
43
nとwordsの文字列は一致していません。
words4?As you make your bed, so you must lie in it.
A bad workman quarrels with his tools.
43
nとwordsの文字列は一致していません。
A bad workman quarrels with his tools.
Every man is the architect of his own fortune.
People who live in glass houses should not throw sA bird in the hand is worth two in the bush.
A bird in the hand is worth two in the bush.
As you make your bed, so you must lie in it.
一分に45文字打ちました:113秒かかりました
と表示されました。時間は測れているのですが、文字列が一致しません
またどうすれば文字列を間違えた時にもう一度入力し直す事が出来るのでしょうか・・・
どなたかお願い致します
問題
英語タイピング練習ソフトを作りたい.以下のような例文を入力した時の、入力にかかった時間を計測し,一分間に何文字入力できる早さであるかを出力するプログラムを作成せよ.入力ミスした際はもう一度行わせる.1分間に入力した文字数と時間を表示すること.
下記の英文は、char *words[5]のようなポインタ配列の初期値として与えるか、別途ファイルに書いておき、そこから読み込むようにする.
エラーは無いです
今は文章が一致しないため『A bad workman quarrels with his tools.』のみを定義しています
英文
↓
A bad workman quarrels with his tools.
Every man is the architect of his own fortune.
People who live in glass houses should not throw stones.
A bird in the hand is worth two in the bush.
As you make your bed, so you must lie in it.
プログラム
↓
/* -*-coding: utf-8-*- */
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char n[5][50];
/*char *words[] = {"A bad workman quarrels with his tools.",
"Every man is the architect of his own fortune.",
"People who live in glass houses should not throw stones.",
"A bird in the hand is worth two in the bush.",
"As you make your bed, so you must lie in it."};*/
int i, len;
time_t start, end;
char words[50] = "A bad workman quarrels with his tools.";
srand(time(NULL));
start = time(NULL);
for(i = 0; i < 5; i++){
printf("words%d?", i);
fgets(n, 500, stdin);
len = strlen(n);
/*len += len;*/
printf("%s\n", words);
printf("%d\n", len - 2);
/*printf("%d\n", strcmp(n, words));*/
if(strcmp(n, words) == 0){
puts("nとwordsの文字列は一致しています。");
}
else{
puts("nとwordsの文字列は一致していません。");
}
}
end = time(NULL);
for(i = 0; i < 5; i++)
printf("%s\n", n);
printf("一分に%d文字打ちました:%.0f秒かかりました", len, difftime(end, start));
return 0;
}
実行結果
↓
./a.out
words0?A bad workman quarrels with his tools.
A bad workman quarrels with his tools.
37
nとwordsの文字列は一致していません。
words1?Every man is the architect of his own fortune.
A bad workman quarrels with his tools.
45
nとwordsの文字列は一致していません。
words2?People who live in glass houses should not throw stones.
A bad workman quarrels with his tools.
55
nとwordsの文字列は一致していません。
words3?A bird in the hand is worth two in the bush.
A bad workman quarrels with his tools.
43
nとwordsの文字列は一致していません。
words4?As you make your bed, so you must lie in it.
A bad workman quarrels with his tools.
43
nとwordsの文字列は一致していません。
A bad workman quarrels with his tools.
Every man is the architect of his own fortune.
People who live in glass houses should not throw sA bird in the hand is worth two in the bush.
A bird in the hand is worth two in the bush.
As you make your bed, so you must lie in it.
一分に45文字打ちました:113秒かかりました
と表示されました。時間は測れているのですが、文字列が一致しません
またどうすれば文字列を間違えた時にもう一度入力し直す事が出来るのでしょうか・・・
どなたかお願い致します