home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list17_4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-16  |  337 b   |  20 lines

  1.  /* The strdup() function. */
  2.  
  3.  #include <stdio.h>
  4.  #include <string.h>
  5.  
  6.  char source[] = "The source string.";
  7.  
  8.  main()
  9.  {
  10.      char *dest;
  11.  
  12.      if ( (dest = strdup(source)) == NULL)
  13.      {
  14.          fprintf(stderr, "Error allocating memory.");
  15.          exit(1);
  16.      }
  17.  
  18.      printf("The destination = %s", dest);
  19.  }
  20.