Growable Score Roster with realloc and Owned Names
hardQuestion 477The struct is given to you:
typedef struct { char *name; int score; } Entry;
Read an integer n (always 1 or more), then n lines, each holding a one-word name (at most 63 characters) and an integer score.
Start with Entry *list = NULL; and capacity 0, and grow the array with realloc as entries arrive - do not allocate all n slots up front. Each entry's name must point at its own heap copy of the word you read, not at the buffer you read into.
Print every entry in input order as the name, a space, and the score. Then print a final line: "Top: " followed by the name and score of the highest scorer. If two entries tie for the highest score, print the one that appeared first.
Sample input: 3 Ada 91 Linus 78 Grace 95
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
Ada 91 Linus 78 Grace 95 Top: Grace 95
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...