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" #include "train.h"
struct car* add_car (struct car* first, const char* target) { 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) { if (novyj_vagon == NULL) {
printf("Chyba: nepodarilo sa vytvorit novy vozen!\n"); printf("Chyba: nepodarilo sa vytvorit novy vozen!\n");
return first; 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->value[SIZE-1] = '/0';
novyj_vagon->next = NULL; novyj_vagon->next = NULL;
@ -23,8 +23,8 @@ struct car* add_car (struct car* first, const char* target) {
while (actual->next !=NULL) { while (actual->next !=NULL) {
actual = actual->next; actual = actual->next;
} }
aktualny->next = novy_vozen; actual->next = novyj_vagon;
return fist; return first;
} }
@ -38,24 +38,16 @@ void print_train (struct car* first) {
int schet = 1; int schet = 1;
while (actual !=NULL) { while (actual !=NULL) {
printf("%d. [%s]", poradie, aktualny->value); printf("%d. [%s]", actual->value);
if (aktualny->next != NULL) { if (actual->next != NULL) {
printf("->"); printf("->");
} }
aktualny = aktualny->next; actual = actual->next;
schet++; schet++;
} }
printf("\n"); printf("\n");
} }
void cancel_train (struct car* first) {
}
struct car* clear_train(struct car* first, const char* target) {
}
int main() { int main() {
return 0; 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