Your question is Debug Pointer and Allocation Errors. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
At The Reynolds and Reynolds Company, dealership inventory is tracked with a singly linked list of vehicle records inside the C module below.
typedef struct VehicleRecord {
char vin[18];
int year;
double price;
struct VehicleRecord *next;
} VehicleRecord;
VehicleRecord *add_vehicle(VehicleRecord *head, const char *vin, int year, double price) {
VehicleRecord *node = malloc(sizeof(VehicleRecord));
strcpy(node->vin, vin);
node->year = year;
node->price = price;
node->next = head;
return node;
}
void remove_vehicle(VehicleRecord *head, const char *vin) {
VehicleRecord *current = head;
while (current != NULL) {
if (strcmp(current->vin, vin) == 0) {
free(current);
return;
}
current = current->next;
}
}
void print_inventory(VehicleRecord *head) {
VehicleRecord *current = head;
while (current != NULL) {
printf("%s (%d): $%.2f
", current->vin, current->year, current->price);
current = current->next;
}
}
Debug this code snippet, which contains a memory allocation or pointer error, and fix every issue you find.