This commit is contained in:
Oleksandr Vyshniakov 2025-11-04 18:28:38 +01:00
parent fd40d81e4f
commit ff6a322c19
3 changed files with 22 additions and 15 deletions

BIN
du4/output/train.exe Normal file

Binary file not shown.

View File

@ -4,14 +4,14 @@
#include "train.h"
struct car* add_car (struct car* first, const char* target) {
struct car* novyj_vagon = (struct car*) malloc(sizeof(struct car*)); //создаём новую строку
struct car* novyj_vagon = (struct car*) malloc(sizeof(struct car)); //создаём новую строку
if (novyj_vagon == NULL) {
printf("Chyba: nepodarilo sa vytvorit novy vozen!\n");
return first;
}
strcpy(novyj_vagon->value, target, SIZE - 1); //Потому что строка в C всегда должна заканчиваться нулём
strncpy(novyj_vagon->value, target, SIZE - 1); //Потому что строка в C всегда должна заканчиваться нулём
novyj_vagon->value[SIZE-1] = '/0';
novyj_vagon->next = NULL;
@ -23,8 +23,8 @@ struct car* add_car (struct car* first, const char* target) {
while (actual->next !=NULL) {
actual = actual->next;
}
aktualny->next = novy_vozen;
return fist;
actual->next = novyj_vagon;
return first;
}
@ -38,24 +38,16 @@ void print_train (struct car* first) {
int schet = 1;
while (actual !=NULL) {
printf("%d. [%s]", poradie, aktualny->value);
if (aktualny->next != NULL) {
printf("%d. [%s]", actual->value);
if (actual->next != NULL) {
printf("->");
}
aktualny = aktualny->next;
actual = actual->next;
schet++;
}
printf("\n");
}
void cancel_train (struct car* first) {
}
struct car* clear_train(struct car* first, const char* target) {
}
int main() {
return 0;
}

View File

@ -0,0 +1,15 @@
#ifndef TRAIN_H
#define TRAIN_H
#define SIZE 100
struct car {
char value[SIZE];
struct car* next;
};
struct car* add_car(struct car* first,const char* target);
void print_train(struct car* first);
void cancel_train(struct car* first);
struct car* clear_train(struct car* first,const char* target);
#endif // TRAIN_H