CJCoding With Joseph
15free / daySign inCreate account

Build Your Own my_strdup

Write my_strdup(s) so it returns a brand-new heap string holding the same characters as s. Then in main: read one word into buf, call my_strdup, and print exactly three lines:

- "Copy: <the copied text>"
- "Length: <number of characters>"
- "Same pointer: <1 if the copy is at the SAME address as buf, otherwise 0>"

For the input:

banana

the output is exactly what is shown in Expected Output.

Print the comparison, never the address itself.

Free the memory you allocate before the program ends — this question checks for memory leaks.

Expected Output:

Copy: banana
Length: 6
Same pointer: 0

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
banana\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.