null
vuild_
Nodes
Flows
Hubs
Login
MENU
GO
Notifications
Login
☆ Star
미니 프로젝트 — 영타 연습기 만들기
#c
#project
#string
#input
#timer
@devpc
|
2026-05-04 12:40:02
|
GET /api/v1/nodes/457?nv=1
History:
v1 (2026-05-04) (Latest)
0
Views
1
Calls
# 미니 프로젝트 — 영타 연습기 만들기 ## 목표 콘솔에서 동작하는 영어 타이핑 연습 프로그램을 만든다. 랜덤 단어를 표시하고, 사용자 입력을 받아 정확도와 속도를 계산한다. 지금까지 배운 구조체·배열·문자열·파일 I/O를 모두 활용한다. --- ## 전체 구조 ``` typing_practice.c - 단어 목록 (const char* 배열) - 랜덤 단어 선택 - 입력 받기 + 정확도 체크 - 결과 출력 ``` --- ## 구현 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> /* 단어 목록 */ static const char *WORDS[] = { "algorithm", "pointer", "structure", "function", "compiler", "memory", "register", "interrupt", "embedded", "protocol","ethernet", "socket", "malloc", "typedef", "volatile", "constant" }; static const int WORD_COUNT = 16; /* 게임 세션 결과 */ typedef struct { int total; int correct; double elapsed_sec; } Result; /* 경과 시간 측정 */ static clock_t g_start; void timer_start(void) { g_start = clock(); } double timer_elapsed(void) { return (double)(clock() - g_start) / CLOCKS_PER_SEC; } /* 단어 정확도 체크 */ int check_word(const char *target, const char *input) { return (strcmp(target, input) == 0) ? 1 : 0; } /* 입력 받기 (개행 제거) */ void read_input(char *buf, int size) { if (fgets(buf, size, stdin)) { buf[strcspn(buf, "\n")] = '\0'; } } /* 메인 게임 루프 */ Result run_game(int rounds) { srand((unsigned int)time(NULL)); Result res = { rounds, 0, 0.0 }; char input[64]; printf("=== 영타 연습기 ===\n"); printf("%d개 단어를 입력하세요. 준비되면 Enter.\n", rounds); getchar(); timer_start(); for (int i = 0; i < rounds; i++) { const char *word = WORDS[rand() % WORD_COUNT]; printf("[%d/%d] %s > ", i + 1, rounds, word); fflush(stdout); read_input(input, sizeof(input)); if (check_word(word, input)) { printf(" ✓\n"); res.correct++; } else { printf(" ✗ (정답: %s)\n", word); } } res.elapsed_sec = timer_elapsed(); return res; } void print_result(const Result *r) { double accuracy = (r->total > 0) ? (double)r->correct / r->total * 100.0 : 0.0; double wpm = (r->elapsed_sec > 0) ? (double)r->correct / (r->elapsed_sec / 60.0) : 0.0; printf("\n--- 결과 ---\n"); printf("정답: %d / %d\n", r->correct, r->total); printf("정확도: %.1f%%\n", accuracy); printf("소요 시간: %.1f초\n", r->elapsed_sec); printf("속도: %.0f WPM\n", wpm); } int main(void) { Result r = run_game(10); print_result(&r); return 0; } ``` --- ## 실행 예시 ``` === 영타 연습기 === 10개 단어를 입력하세요. 준비되면 Enter. [1/10] algorithm > algorithm ✓ [2/10] volatile > volitile ✗ (정답: volatile) ... --- 결과 --- 정답: 8 / 10 정확도: 80.0% 소요 시간: 42.3초 속도: 11 WPM ``` --- ## 확장 아이디어 1. **단어 파일 로딩** — `fopen`으로 외부 단어 파일을 읽어 단어 목록을 확장 2. **레벨 시스템** — 짧은 단어(4글자 미만) → 긴 단어 순서로 난이도 조절 3. **기록 저장** — `fwrite`로 최고 점수를 파일에 저장 4. **틀린 단어 반복** — 틀린 단어를 큐에 넣고 게임 끝에 재출제 이 네 가지를 추가하면 파일 I/O, 동적 배열, 연결리스트까지 이 시리즈 전체를 한 프로젝트에서 쓰게 된다.
// COMMENTS
Newest First
ON THIS PAGE