#include "a_train.h" #include #include #include int main() { struct car* train = NULL; int choice; char station[100]; while (1) { printf("\nMenu:\n"); printf("1. Add station\n"); printf("2. Remove a station\n"); printf("3. Print route\n"); printf("4. Cancel train\n"); printf("5. Exit\n"); printf("Enter your choice: "); scanf("%d", &choice); getchar(); switch(choice) { case 1: while (1) { printf("Enter the station name to add (or press Enter to stop): "); fgets(station, sizeof(station), stdin); station[strcspn(station, "\n")] = '\0'; // Remove newline character if (station[0] == '\0') { break; // Exit the loop if input is empty } train = add_car(train, station); printf("Station '%s' added to the train.\n", station); } break; case 2: while (1) { printf("Enter the station name to clear (or press Enter to stop): "); fgets(station, sizeof(station), stdin); station[strcspn(station, "\n")] = '\0'; // Remove newline character if (station[0] == '\0') { break; // Exit the loop if input is empty } struct car* temp = train; int found = 0; while (temp != NULL) { if (strcmp(temp->value, station) == 0) { found = 1; break; } temp = temp->next; } if (found) { train = clear_train(train, station); printf("Station '%s' deleted from the train.\n", station); } else { printf("Station '%s' does not exist in the train.\n", station); } } break; case 3: printf("\nRoute List:\n"); print_train(train); break; case 4: printf("\nCanceling the train...\n"); cancel_train(train); train = NULL; break; case 5: printf("Exiting program...\n"); cancel_train(train); return 0; default: printf("Invalid choice, please try again.\n"); } } return 0; }