strncpy 로 메모리 복사

|


man strncpy wrote:
The strncpy() function is similar, except that not more than n bytes of
src are copied. Thus, if there is no null byte among the first n bytes
of src, the result will not be null-terminated.

이렇게 명시되어 있으니까요...

strncpy( dst, src, n );
dst[n] = '\0';

정도면 되지 않을까 싶은데요 :)
길이가 n보다 짧다면 null 까지 복사될테고... 아니라면 null terminated 라는 보장이 없으니까 후자일 경우에 한해서 문제를 일으키지 않도록 해주면 되겠죠

'잡다한것들전부 > C, C++, C#' 카테고리의 다른 글

추상 클래스 (C++)  (0) 2014.01.10
Duff's Device  (0) 2014.01.10
c++ 11 이란??  (0) 2014.01.09
strncpy 로 메모리 복사  (0) 2014.01.07
C언어 배열 초기화 방법  (0) 2014.01.07
c++ stl 관련 자료  (0) 2014.01.06
Trackback 0 And Comment 0