Duplicate a string.

char * strdup(
	const char * s1)

The strdup() function allocates memory and copies into it the string addressed by s1, including the terminating null character.

Warning

The strdup() function calls malloc() to allocate the memory for the duplicated string! The user is responsible for freeing the memory by calling free().

Returns

The strdup() function returns a pointer to the resulting string dest. If malloc() cannot allocate enough storage for the string, strdup() will return NULL.

Warning

Be sure to check the return value of the strdup() function to make sure that the function has succeeded in allocating the memory!