Create a duplicate of a string
#include <string.h> char* strdup( const char* src );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The strdup() function creates a duplicate of the string pointed to by src, and returns a pointer to the new copy.
A pointer to a copy of the string, or NULL if an error occurred (errno) is set.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main( void )
{
char *dup;
dup = strdup( "Make a copy" );
printf( "%s\n", dup );
free (dup);
return EXIT_SUCCESS;
}
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | No |
| Thread | Yes |