// Starter code for prac_q10. // Create your order management system here! #include #include #include #define MAX_LEN 20 enum order_type { BUY, SELL }; struct order { enum order_type type; int price; int quantity; struct order *next; }; struct order *read_orders(void); int main(void) { struct order *order_list = read_orders(); // TODO: Implement your solution here! } // This function reads in a list of orders, ending with either // a blank line, or EOF. // Returns: A pointer to the head of the linked list struct order *read_orders(void) { char line[MAX_LEN]; struct order *head = NULL; struct order *tail = NULL; while (fgets(line, MAX_LEN, stdin) != NULL && strcmp(line, "\n")) { struct order *new = malloc(sizeof(struct order)); new->next = NULL; char order_char; sscanf(line, "%c %d %d", &order_char, &new->quantity, &new->price); new->type = (order_char == 'b') ? BUY : SELL; if (head != NULL) { tail->next = new; tail = new; } else { head = tail = new; } } return head; }