×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: C
Posted by: Rob Green
Added: Sep 30, 2019 2:03 PM
Modified: Sep 17, 2022 10:27 AM
Views: 4061
Tags: char
  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. }