[C언어] String.h 라이브러리 함수 - strdup() 함수 파헤치기
memcpy 함수의 헤더 파일 #include strdup() 함수의 원형 char * strdup(const char *string); Parameter string 데이터를 복사할 주소이고 const char * 형으로 전달된다. 리턴값 복사된 데이터의 주소을 리턴하고 에러가 발생시 NULL 값이 리턴된다. strdup 함수는 단순히 문자열 복사만 하는 strcpy에 추가적으로 메모리 할당을 해주는 함수이다. 그렇기 때문에 stdup 함수를 사용한 이후에는 free 를 항상 해주셔야 됩니다. strdup 예제코드 #include #include int main(){ char * str = "hello world!!"; char *newstr; newstr = strdup(str); printf("**..