タイプ練習のサンプル
プログラム内に辞書を用意。
#include <conio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> char *dic[] = { "int", "short", "long", "char", "float", "double", "void", "unsigned", "hello", "world", "include", "time", "struct", "return", "printf", "sizeof", "while", "main", "static", "extern", "switch", "case", "continue", "volatile", "default", "goto" }; int typing() { int c; int p; int size; int i; time_t start; time_t end; char buff[256]; size = sizeof(dic) / sizeof(dic[0]); printf("キーを押すとスタート\n"); c = _getch(); start = time(NULL); srand(start); for (i = 0; i < 10; i++) { p = rand() % size; printf("%s\n", dic[p]); while (1) { scanf("%s", buff); if (strcmp(buff, dic[p])) { puts("再入力"); } else { break; } } } end = time(NULL); printf("%d秒", end - start); return 0; }