diff --git a/du4/output/train.exe b/du4/output/train.exe new file mode 100644 index 0000000..a900acb Binary files /dev/null and b/du4/output/train.exe differ diff --git a/du4/train.c b/du4/train.c index 899aabe..f234435 100644 --- a/du4/train.c +++ b/du4/train.c @@ -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; } \ No newline at end of file diff --git a/du4/train.h b/du4/train.h index e69de29..2356929 100644 --- a/du4/train.h +++ b/du4/train.h @@ -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 \ No newline at end of file