Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION2 (20marks) Consider the following program: #include #include #include #

ID: 3920938 • Letter: Q

Question

QUESTION2 (20marks) Consider the following program: #include #include #include #de fine SIZE 50 void insert name (char 1ist, char name, int size): void print list (char list, int size) void save_list (FILE fp, char ist, int size)i int main) FILE p: char name [SIZE) char temp 130]: int size0, choice 0 do f printf("MENU: nl: To insert a name ") printf ("2: To print all names in the listIn") printf("3: Load a list "); printf(4: Save the listln") printf(S: Exit Programn") printf ("Your choice: ) scanf("%d", sehoice) ; if (choice1) f if (size

Explanation / Answer

Answer 2.4
*************

void insert_name(char **list, char *name, int *size) {

if(*size < SIZE) {

list[*size] = (char *)malloc((strlen(name) + 1) * sizeof(char));

strcpy(list[*size], name);

*size += 1;

}

}

Answer 2.5
*************

void print_list(char **list, int size) {

for(int i=0; i<size; i++) {

cout << list[i] << endl;

}

}

Answer 2.6
*************

void save_list(FILE *fp, char **list, int size) {

for(int i=0; i<size; i++) {

fprintf(fp, "%s ", list[i]);

}

fclose(fp);

}

Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote