I work with a method that displays only one car by its registration number. My structure:
struct car { char registration[10]; char model[30]; char colour[30]; int num; bool reserved; long amount; }; struct LinearNode { struct car *element; struct LinearNode *next; };
I call the method in the menu as follows:
char reg[10]; printf("Input car registration:"); scanf("%s", reg); viewSpecificNodes(reg);
And then the method itself:
void viewSpecificNodes(char *reg) { int string; struct LinearNode *current, *previous; bool notFound = true; if (isEmpty()) printf("Error - there are no cars in the list\n"); else { current = front; while (current != NULL) { string = strcmp(reg, current->element->registration); if (string = 0){ printf("Registration: %s\n", current->element->registration); printf("Model: %s\n", current->element->model); printf("Colour: %s\n", current->element->colour); printf("Number of previous owners: %d\n", current->element->num); if(current->element->reserved==0){ printf("Car is unreserved\n"); }else{ printf("Car is reserved\n"); } printf("Reserve amount: %li\n", current->element->amount); } else { printf("This car does not exist"); }
current = current-> next; }}} // end viewSpecificNode
I decided that my string string == 0
is an error, because right at the beginning I have the following expression:
#define bool int //defining my own verion of boolean #define true 1 #define false 0
and changed the line to string == 1
. In the end, nothing matters.
This method simply does not work and causes nothing.