C examples for String:String Function
Use non-ANSI strdup() function.
#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; }