Files
2nd/10_Wiki/Topic_Programming/Topic_C/C_Strings_Functions.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

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
strlen strcat strcpy strcmp
string.h
C 문자열 함수
B 0.86 2026-07-04 2026-07-04
c
programming-language
w3schools
strings
string-functions
https://www.w3schools.com/c/c_strings_functions.php

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 \0 terminator. [S1]
  • sizeof(arr) — returns the array's total allocated memory in bytes, INCLUDING the \0 and any unused trailing space — not the string's actual content length. [S1]
  • strcat(dest, src) — appends src onto the end of dest; dest's buffer must be large enough to hold both strings combined. [S1]
  • strcpy(dest, src) — copies src's value into dest; dest's buffer must be large enough for the copied content. [S1]
  • strcmp(str1, str2) — returns 0 if the strings are equal, a non-zero value otherwise. [S1]

📖 세부 내용 (Details)

  • strlen vs sizeof on an exactly-sized array: char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; strlen(alphabet) // 26, sizeof(alphabet) // 27 (27 includes \0). [S1]
  • strlen vs sizeof on 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)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C String Functions" page (Astra wiki-curation, P-Reinforce v3.1 format).