Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C
Posted by: patrick cea
Added: Sep 30, 2019 2:03 PM
Views: 4
Tags: no tags
  1. char *strdup (const char *s) {
  2.     char *d = malloc (strlen (s) + 1);   // Space for length plus nul
  3.     if (d == NULL) return NULL;          // No memory
  4.     strcpy (d,s);                        // Copy the characters
  5.     return d;                            // Return the new string
  6. }