strncpy

strncpy

anton
커버 strncpy

strncpy란?

문자열의 일부만 복사하는 함수

strncpy(목적지, 원본, 복사할_글자수);

기본 예제

char str[20] = "mango tree";
strncpy(str, "apple-pie", 5);  // 5글자만 복사
printf("%s\n", str);           // 결과: "apple tree"

동작 과정:

원본:    "mango tree"
복사:    "apple" (5글자만)
결과:    "apple tree"
         ↑↑↑↑↑
         덮어씀
  • anton
    토픽 71  /  봤어요 16

댓글

댓글 본문