Question: In C Language - Starter Code Provided Given the starter code, create three functions that initialize a linked list from the input file car.txt. Three
In C Language - Starter Code Provided
Given the starter code, create three functions that initialize a linked list from the input file "car.txt".
Three functions needed:


![Three functions needed: Starter Code: typedef struct car { char type[15]; //](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f4532eb50b2_11066f4532e526f8.jpg)
Starter Code:
typedef struct car { char type[15]; // sports car, truck, convertible etc char make[20]; char model[30]; char engine[15]; // V6, V8, V4 etc int hp; // horse power char color[25]; int length; // length of car in feet double base_price; double total_price; accessories_t extras; struct car *next; } car_s;
typedef struct list { car_s *head; car_s *tail; int size; } list_t;
void listInitializer (list_t *list, FILE *inFile); void initializeFromFile (list_t *list, FILE *inFile); car_s *newCar (FILE *inFile);
int main(int argc, char **argv) { list_t *list=newList();
FILE* inFile = NULL; //Opening .txt file inFile = fopen(argv[1], "r");
//Error message if null or does not exist, return -1 if (inFile == NULL){ printf("Could not open file. "); return -1; // -1 indicates error }
initializeFromFile (list, inFile);
return 0; }
list_t *newList() //Creating list { list_t *point = (list_t *)malloc(sizeof(list_t));
point->head = NULL; point->tail = NULL; point->size = 0;
return point; }
car.txt
sport car,BMW,330i,V6,700,Red,13,134595.00,135945.00,1,200,0,250,450,450,0
truck,Ford,F150,V8,550,Green,13,86430.00,87630.00,0,0,250,200,500,250,0
sport car,Mercedes,sl500,V6,440,Blue,13,26895.00,27745.00,0,250,0,0,350,250,0
void initializeFromFile (list_t *list, FILE *inFile); -Calls the listInitializer() function, which sends the input file pointer -Calls listInitializer() in a loop until the end of the file void listInitializer (list t *list, FILE *in File); This function is called from initializeFromFile(): This funtion calls newCar () to create and initialize a new car from the file which it then adds to the end of the list. This function also increments the list size for each car added. car S *newcar (FILE *inFile); - Called by the listInitializer () function. Creates and initializes a new car node from the input file pointer passed in. Returns a pointer to the car that was just created. void initializeFromFile (list_t *list, FILE *inFile); -Calls the listInitializer() function, which sends the input file pointer -Calls listInitializer() in a loop until the end of the file void listInitializer (list t *list, FILE *in File); This function is called from initializeFromFile(): This funtion calls newCar () to create and initialize a new car from the file which it then adds to the end of the list. This function also increments the list size for each car added. car S *newcar (FILE *inFile); - Called by the listInitializer () function. Creates and initializes a new car node from the input file pointer passed in. Returns a pointer to the car that was just created
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
