Initializacia

This commit is contained in:
Kozar 2024-10-20 12:58:05 +00:00
parent 6448cb0e4d
commit 2e25765e5d

View File

@ -3,20 +3,22 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct car* add_car(struct car* first,const char* target) { struct car* add_car(struct car* first, const char* target) {
struct car* last = first; struct car* last = first;
struct car* newcar* = calloc(1, sizeof(struct car)); struct car* newcar = calloc(1, sizeof(struct car));
strcpy(newcar->value, target); strcpy(newcar->value, target);
if (last != NULL){
if (last != NULL) {
struct car* current = last; struct car* current = last;
while(current->next != NULL){ while (current->next != NULL) {
current = current->next current = current->next;
} }
current->next = newcar; current->next = newcar;
} else{ } else {
last = newcar; last = newcar;
return last; return last;
} }
return first; return first;
} }