Step 4 of 9
calloc and strdup-style copies
calloc(count, size)allocates and zeroes the memory.- To keep a copy of a string, allocate
strlen(s) + 1bytes (the +1 is for'\0') and copy it in.
Your turn: write char *copy_string(const char *s) that returns a new heap copy of s.
Previous: Return heap memory from a function Next: Growing with realloc