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

Why won\'t this code run properly? This code is exactly as written from my textb

ID: 3575875 • Letter: W

Question

Why won't this code run properly? This code is exactly as written from my textbook.

/*
* Program that builds an ordered list through insertions and then modifies
* it through deletions.
*/

#include <stdio.h>

typedef struct list_node_s {
int key;
struct list_node_s *restp;
} list_node_t;

typedef struct {
list_node_t *headp;
int size;
} ordered_list_t;

list_node_t *insert_in_order(list_node_t *old_listp, int new_key);
void insert(ordered_list_t *listp, int key);
int delete(ordered_list_t *listp, int target);
void print_list(ordered_list_t list);

#define SENT -999

int
main(void)
{
int next_key;
ordered_list_t my_list = {NULL, 0};

/* Creates list through in-order insertions */
printf("Enter integer keys--end list with %d ", SENT);
for (scanf("%d", &next_key);
   next_key != SENT;
   scanf("%d", &next_key)) {
   insert(&my_list, next_key);
}

/* Displays complete list */
printf(" Ordered list before deletions: ");
print_list(my_list);

/* Deletes nodes as requested */
printf(" Enter a value to delete or %d to quit> ", SENT);
for (scanf("%d", &next_key);
   next_key != SENT;
   scanf("%d", &next_key)) {
   if (delete(&my_list, next_key)) {
       printf("%d deleted. New list: ", next_key);
       print_list(my_list);
   } else {
       printf("No deletion. %d not found ", next_key);
   }
}

return (0);
}

Explanation / Answer

The program can not get executed without errors unless you define below functions

which are referenced in your program.

If you still proceed to compile this program without defination of above functions, the compiler(for example)

throws below errors

/tmp/ccrP78ZM.o: In function `main':
p.c:(.text+0x50): undefined reference to `insert'
p.c:(.text+0x8d): undefined reference to `print_list'
p.c:(.text+0xca): undefined reference to `delete'
p.c:(.text+0xf5): undefined reference to `print_list'
collect2: error: ld returned 1 exit status

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