Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**MUST BE DONE IN C PROGRAMMING LANGUAGE** Program adds a car to a linked list in C Modify the given append_to_list function to do the

**MUST BE DONE IN C PROGRAMMING LANGUAGE**

Program adds a car to a linked list in C

Modify the given append_to_list function to do the following

image text in transcribed

Given Code:

struct car *append_to_list(struct car *list){

struct car* newCar = (struct car*)malloc(sizeof(struct car)); newCar->next = NULL;

printf("Enter Car Manufacturer : "); read_line(newCar->make, LEN); printf("Enter Model: "); read_line(newCar->model, LEN); printf("Enter Color: "); read_line(newCar->color, LEN); printf("Enter year: "); scanf("%d", &newCar->year); printf("Enter City MPG: "); scanf("%d", &newCar->city_mpg); printf("Enter Highway MPG: "); scanf("%d", &newCar->highway_mpg); printf("Enter Quantity: "); scanf("%d", &newCar->quantity);

if(list == NULL) { return newCar; } else { struct car* ptr = list; while(1) { if( (strcmp(ptr->make, newCar->make)==0) && (strcmp(ptr->model, newCar->model)==0) && (strcmp(ptr->color, newCar->color)==0) && (ptr->year == newCar->year) && (ptr->city_mpg == newCar->city_mpg) && (ptr->highway_mpg == newCar->highway_mpg) && (ptr->quantity == newCar->quantity) ) { printf("Car already exists in the list. "); return list; } if(ptr->next != NULL) { ptr = ptr->next; } else { break; } } ptr->next = newCar;

return list; }

return NULL; }

The cars will be inserted into an ordered list (by make, then model, then color, then year) and the list remains ordered after the insertion. An example ordering of a list of cars: ford escape blue 2010 ford escape blue 2012 ford escape blue 2017 ford escape red 2010 ford escape white 2014 ford taurus silver 2005 jeep wrangler black 2007 Jeep wrangler black 2017

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

More Books

Students also viewed these Databases questions

Question

2. What should an employer do when facing an OSHA inspection?

Answered: 1 week ago