// The following code is meant to ask the user to continuously enter **char** // inputs, to be inserted at the head of a linked list until CTRL+D is pressed. // // Inputs that are not digits (between 0-9 inclusive) result in "Input // '[character]' is not a digit!" being printed, and not adding to the linked // list. This means that only digit inputs can be added to the linked list. // // The list is printed after CTRL+D is pressed, which should result in printing // all digits scanned in, in reverse order. // // However, there are a number of issues found in the code that you need to fix // Good luck! #include #include struct node { int data; struct node *next; }; struct node *prepend_list(struct node *list, int data); void print_list(struct node *list); int main(void) { struct node *list = NULL; char input; printf("Enter digits:\n"); int success = scanf(" %c", &input); while (success == 0) { if (input <= '0' && input > '9') { printf("Input '%c' is not a digit!\n", input); } else { list = prepend_list(list, input); } success = scanf(" %c", input); } print_list(list); return 0; } // Prints all elements in the given `list` void print_list(struct node *list) { struct node *curr = list; while (curr != NULL) { printf("%d ", curr->data); curr = curr->next; } printf("\n"); } // Creates and adds a new node with given `data` to the head of a given `list`. // Returns a pointer to this new head. struct node *prepend_list(struct node *list, int data) { struct node *new = malloc(sizeof(struct node)); new->data = data; new->next = NULL; return new; }