Question: Please fix my error please. inputs: 1050 2050 2270 3050 3280 3330 3380 4050 4330 4520 4850 4970 4980 result should be the printed numbers

Please fix my error please.

inputs:

1050

2050

2270

3050

3280

3330

3380

4050

4330

4520

4850

4970

4980

result should be the printed numbers with the ascending order.

Howwver, when I run the code, it just print 1050 and then it prints out 2050 infinitely...

#include #include typedef struct node_ { int data; struct node_* next; }node; void print_list(struct node_* list) { struct node_ *temp = list; while(temp != NULL) { printf("%d ", temp->data); temp = temp->next; } } void free_list(struct node_* list) { struct node_* tmp; while (list != NULL) { tmp = list; list = list->next; free(tmp); } } void create_list(struct node_** head_ref, int new_data){ struct node_* new_node = (struct node_*) malloc(sizeof(struct node_)); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node; } int main(int argc, char* argv[]) { if(argc != 2) { printf("Error, Please run program as follows: "); printf("./a.out input.txt "); return 0; } struct node_* head = NULL; FILE *fp = fopen(argv[1],"r"); int new_data; while( fscanf(fp, "%d", &new_data) != EOF ){ create_list(&head,new_data); printf("Given linked list "); print_list(head); free_list(head); getchar(); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!