Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions