2024-10-24 16:25:36 +00:00
|
|
|
#include "a_train.h"
|
2024-11-19 14:48:04 +00:00
|
|
|
#include <stdlib.h>
|
2024-10-24 16:25:36 +00:00
|
|
|
#include <stdio.h>
|
2024-11-19 14:48:04 +00:00
|
|
|
#include <string.h>
|
2024-10-24 16:25:36 +00:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
struct car* train = NULL;
|
2024-11-19 14:48:04 +00:00
|
|
|
char input[SIZE];
|
|
|
|
int option;
|
2024-10-24 16:25:36 +00:00
|
|
|
|
2024-11-19 14:48:04 +00:00
|
|
|
do {
|
|
|
|
printf("\n--- Train Management ---\n");
|
|
|
|
printf("1. Add a car to the train\n");
|
|
|
|
printf("2. Print the train\n");
|
|
|
|
printf("3. Remove cars to Levoča\n");
|
|
|
|
printf("4. Exit\n");
|
|
|
|
printf("Select an option: ");
|
|
|
|
scanf("%d", &option);
|
|
|
|
getchar(); // Считываем символ новой строки после ввода числа
|
2024-10-24 16:25:36 +00:00
|
|
|
|
2024-11-19 14:48:04 +00:00
|
|
|
switch (option) {
|
|
|
|
case 1:
|
|
|
|
printf("Enter the destination: ");
|
|
|
|
fgets(input, SIZE, stdin);
|
|
|
|
input[strcspn(input, "\n")] = '\0'; // Удаляем символ новой строки
|
|
|
|
train = add_car(train, input);
|
|
|
|
printf("Car added to the train.\n");
|
|
|
|
break;
|
2024-10-24 16:25:36 +00:00
|
|
|
|
2024-11-19 14:48:04 +00:00
|
|
|
case 2:
|
|
|
|
print_train(train);
|
|
|
|
break;
|
2024-10-24 16:25:36 +00:00
|
|
|
|
2024-11-19 14:48:04 +00:00
|
|
|
case 3:
|
|
|
|
train = clear_train(train, "Levoča");
|
|
|
|
printf("All cars to Levoča have been removed.\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
printf("Exiting and releasing memory.\n");
|
|
|
|
cancel_train(train);
|
|
|
|
train = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Invalid option. Please try again.\n");
|
|
|
|
}
|
|
|
|
} while (option != 4);
|
2024-10-24 16:25:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|