1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
4.4 KiB
4.4 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| c-strings-functions | C String Functions | Programming_Language | draft | conceptual |
|
B | 0.86 | 2026-07-04 | 2026-07-04 |
|
|
C String Functions
🎯 한 줄 통찰 (One-line insight)
strlen() and sizeof() measure fundamentally different things and diverge sharply once a buffer is oversized — for a 26-letter alphabet stored in a 50-byte array, strlen() still correctly reports 26 (it counts up to the \0), while sizeof() reports 50 (the array's total allocated memory), meaning sizeof is NEVER a reliable way to get "string length" once the array is larger than the string it holds. [S1]
🧠 핵심 개념 (Core concepts)
<string.h>— the header required to use C's built-in string functions. [S1]strlen(str)— returns the string's character count UP TO (not including) the\0terminator. [S1]sizeof(arr)— returns the array's total allocated memory in bytes, INCLUDING the\0and any unused trailing space — not the string's actual content length. [S1]strcat(dest, src)— appendssrconto the end ofdest;dest's buffer must be large enough to hold both strings combined. [S1]strcpy(dest, src)— copiessrc's value intodest;dest's buffer must be large enough for the copied content. [S1]strcmp(str1, str2)— returns0if the strings are equal, a non-zero value otherwise. [S1]
📖 세부 내용 (Details)
strlenvssizeofon an exactly-sized array:char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; strlen(alphabet) // 26, sizeof(alphabet) // 27(27 includes\0). [S1]strlenvssizeofon an OVERSIZED array — the critical divergence:char alphabet[50] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; strlen(alphabet) // still 26, sizeof(alphabet) // 50(the array's declared capacity, not content length). [S1]- Concatenation requiring a big-enough destination buffer:
char str1[20] = "Hello "; char str2[] = "World!"; strcat(str1, str2); printf("%s", str1);. [S1] - Comparison returning 0 for equal strings, non-zero otherwise:
strcmp(str1, str2); // 0 if equal/strcmp(str1, str3); // -4 if not equal. [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
- sizeof는 문자열 길이 측정 도구가 아님: 배열 크기가 실제 문자열보다 클 경우 sizeof는 할당된 전체 메모리(50)를 반환하지만 strlen은 여전히 실제 내용 길이(26)를 정확히 반환한다는 점이 명시적으로 대비됨 — sizeof를 문자열 길이 측정에 쓰면 안 된다는 강력한 경고. [S1]
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — strcat으로 "Hello "와 "World!"를 합치는 예제가 문자열 연결의 표준 실전 활용이며, 대상 버퍼 크기를 미리 충분히 확보해야 한다는 주의사항이 함께 강조된다. [S1]
💻 코드 패턴 (Code patterns)
strlen() and sizeof() diverging once the buffer is larger than the actual string content (C):
char alphabet[50] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
printf("%zu\n", strlen(alphabet)); // 26 (actual content length)
printf("%zu\n", sizeof(alphabet)); // 50 (total allocated buffer size)
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.86
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: C Tutorial
- 관련 개념: C Strings Esc, C Data Types Sizeof, C Math
- 참조 맥락: 문자열 섹션 마지막 — 수학 함수(Math) 섹션으로 이어짐.
📚 출처 (Sources)
- [S1] W3Schools — C String Functions — https://www.w3schools.com/c/c_strings_functions.php
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C String Functions" page (Astra wiki-curation, P-Reinforce v3.1 format).