Use non-ANSI strdup() function. - C String

C examples for String:String Function

Description

Use non-ANSI strdup() function.

Demo Code

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char source[] = "The source string.";

int main( void )
{
    char *dest;/*from  w  ww. j  a v a 2s. c om*/

    if ( (dest = strdup(source)) == NULL)
    {
        fprintf(stderr, "Error allocating memory.");
        exit(1);
    }

    printf("The destination = %s\n", dest);
    return 0;
}

Result


Related Tutorials