Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Function Definitions needed to be filled ( list_t *newList() has already been completed) : 1. Given the current starter code, fill in the function definitions
Function Definitions needed to be filled ( list_t *newList() has already been completed) :
1. Given the current starter code, fill in the function definitions stated above (the function list_t *newList() has already been completed).
typedef struct car { char make[20]; char model[30]; char color [25]; char trim[15); double basePrice; double finalPrice; char engine[15]; int torque; int horsepower; int carLength; carAccessories_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], ""); //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_t *list, FILE *inFile); return 0; } list_t *newList() { list_t *point = (list_t *)malloc(sizeof(list_t)); point->head = NULL; point->tail = NULL; point->size = 0; return point; } list t *newList (); Creates a new list; initializes the head, tail, and size pointers. Returns a pointer to the new list. void listInitializer (list_t *list, FILE *inFile); 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. void initializeFromFile (list_t *list, FILE *inFile); -Calls the listInitializer () function, which sends the input file pointer (the file specified at command-line and opened in int main(int argc, char *argv) ) -Calls listInitializer () in a loop until the end of the file 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. typedef struct car { char make[20]; char model[30]; char color [25]; char trim[15); double basePrice; double finalPrice; char engine[15]; int torque; int horsepower; int carLength; carAccessories_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], ""); //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_t *list, FILE *inFile); return 0; } list_t *newList() { list_t *point = (list_t *)malloc(sizeof(list_t)); point->head = NULL; point->tail = NULL; point->size = 0; return point; } list t *newList (); Creates a new list; initializes the head, tail, and size pointers. Returns a pointer to the new list. void listInitializer (list_t *list, FILE *inFile); 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. void initializeFromFile (list_t *list, FILE *inFile); -Calls the listInitializer () function, which sends the input file pointer (the file specified at command-line and opened in int main(int argc, char *argv) ) -Calls listInitializer () in a loop until the end of the file 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 createdStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started