CJCoding With Joseph
15free / daySign inCreate account

Deep Copy a Player with a char* Name

The Player struct is provided. Write:

- make_player(name, score): allocate a Player on the heap AND give it its own heap copy of name, then return it
- free_player(p): free everything make_player allocated

Then in main: read a word and an int into buf and score, build the player, then OVERWRITE the buffer with strcpy(buf, "CHANGED") and print exactly three lines:

- "Name: <the player's name>"
- "Score: <the player's score>"
- "Buffer: <the contents of buf>"

For the input:

alice 42

the output is exactly what is shown in Expected Output.

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

Expected Output:

Name: alice
Score: 42
Buffer: CHANGED

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

Hints4 available
Topics:
Pointers
📥 Auto-Input:
alice 42\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.