Hi, im learning about linked lists, and trying to understand how to add elements , or in this care info about a car at the tail end of a linked list. Could anyone point me in the right direction please on how they work, and how i can sort of proceed here?
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_LENGTH 25
struct car
{
int year;
double price;
char model[MAX_LENGTH];
char type[MAX_LENGTH];
int carId; // this is auto-generated by the program
// must be unique for each car
struct car * nextCar;
};
void addNewCar (struct car ** headLL){
/* This option calls a function named addNewCar that prompts the user to enter car data from
standard input and add their information to the end of the linked list passed as a parameter to
this function. The user enters the model, type of the car, its price and year of manufacture
This function must store new cars at the tail end of the current linked list.*/
// we can start by creating a new node that'll hold the car info, and allocate memory too
struct car *newNode = (struct car*)malloc(sizeof(struct car));
// if the new car or node is empty, we need to check
if (newNode == NULL){
printf("memory couldnt be allocated\n");
return;
}
printf("Enter car model\n");
scanf("%s", newNode->model);
printf("Enter car type:\n");
scanf("%s", newNode->type);
printf("Enter its year of manufacture:\n");
scanf("%d", &newNode->year);
printf("Enter price: CDN $");
scanf("%lf", newNode->price);
}```