refresh
This commit is contained in:
parent
fd40d81e4f
commit
ff6a322c19
BIN
du4/output/train.exe
Normal file
BIN
du4/output/train.exe
Normal file
Binary file not shown.
22
du4/train.c
22
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;
|
||||
}
|
||||
15
du4/train.h
15
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
|
||||
Loading…
Reference in New Issue
Block a user