Deep Copy a Player with a char* Name
mediumQuestion 458The 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
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.