c program nano (Memory allocation) Consider typedef struct {char name [20]; int
ID: 3832034 • Letter: C
Question
c program
nano
(Memory allocation) Consider typedef struct {char name [20]; int balance; int gain;} Player; int n; Player *p; scanf ("%d", &n;); ..... Complete the code above by allocating a memory for n players each of which of type Player and making p point to the start of that memory (or in other words, making p have the value of the starting address of that memory). [Recall the slides on dynamic memory (Linked Lists) Consider typedef strut node {char name [20]; struct node *next;} Node; Write a C function with the following prototype Node *find (char *name, Node *head Node *tail) where name is a string, head points to the first node of a linked list and tail points to the last node of the linked list. The function returns the address of the first node whose name is equal to name. It returns NULL if no node of the linked list contain name. No standard library function is allowed except those for strings.Explanation / Answer
2)
int n;
Player *p;
scanf("%d", &n);
p = (Player *)malloc(sizeof(Player)*n);
3)
Node *find(char *name, Node *head, Node *tail){
while(head <= tail){
if(strcmp(head->name, name) == 0)
return head;
head = head->next;
}
return NULL;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.