← Back to Pointers
Question 458
Deep Copy a Player with a char* Name
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 withstrcpy(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
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.