Compare commits

..

2 Commits

Author SHA1 Message Date
1fe8245bf7 1 2024-10-24 18:57:01 +02:00
a3f63c348e 1 2024-10-24 18:56:50 +02:00

View File

@ -2,18 +2,33 @@
#define TRAIN_H #define TRAIN_H
#define SIZE 100 #define SIZE 100
/**
* Jeden vozen vlaku struct car* add_car(struct car* first, const char* target) {
*/ // Vytvorenie noveho vozna
struct car { struct car* new_car = (struct car*)malloc(sizeof(struct car));
/** if (new_car == NULL) {
* Nazov cielovej stanice printf("Chyba: Nepodarilo sa alokovať pamäť pre nový vozeň.\n");
*/ return first;
char value[SIZE]; }
/**
* Smenik na dalsi vozen // Inicializacia hodnot
*/ strncpy(new_car->value, target, SIZE);
struct car* next; new_car->next = NULL;
// Ak vlak neexistuje, novy vozen sa stane prvym
if (first == NULL) {
return new_car;
}
// Najdenie posledneho vozna
struct car* temp = first;
while (temp->next != NULL) {
temp = temp->next;
}
// Pridanie noveho vozna na koniec
temp->next = new_car;
return first;
}; };
/** /**