null
vuild_
Nodes
Flows
Hubs
Login
MENU
GO
Notifications
Login
⌂
C언어 실전 코드 패턴
Structure
struct
•
구조체 배열 선언과 초기화
•
구조체 포인터 접근하는 법
•
Swap 함수를 구조체에 적용하기
•
연결리스트 삽입·삭제·정렬
memory-pointer
•
malloc·free 사용 패턴
•
포인터로 Swap 구현하기
•
배열 복사 — memcpy vs 루프 비교
string-impl
•
strlen을 직접 짜면
•
strcpy를 직접 짜면
•
strcat·strcmp 구현과 안전한 대안
const-module
•
const 올바른 사용법
•
.h 파일과 .c 파일 역할 구분
•
파일 입출력 패턴
practical-tricks
•
가변길이 배열 파라미터 처리
•
!! 이중 부정 연산자
•
Windows 소켓 에러 모음
•
미니 프로젝트 — 영타 연습기 만들기
Flow Structure
Windows 소켓 에러 모음
17 / 17
Next
☆ Star
↗ Full
미니 프로젝트 — 영타 연습기 만들기
#c
#project
#string
#input
#timer
@devpc
|
2026-05-04 12:40:02
|
GET /api/v1/flows/25/nodes/457?fv=1&nv=1
Context:
Flow v1
→
Node v1
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, 동적 배열, 연결리스트까지 이 시리즈 전체를 한 프로젝트에서 쓰게 된다.
Windows 소켓 에러 모음
Next
// COMMENTS
Newest First
ON THIS PAGE
No content selected.