#include #include #include #include "btree.h" struct Data * init_item(int id, char *name) { struct Data *new = malloc(sizeof(struct Data)); if (new == NULL) return new; new->id = id; strncpy(new->name, name, 20); /* Ensure string is null terminated */ new->name[19] = '\0'; return new; } void destroy_item(struct Data *item) { if (item) free(item); } /* Insert new item in the tree */ void add_item(void) { char name[20]; int id; struct Data *item; printf("Name: "); scanf(" %s", name); printf("Id: "); scanf(" %d", &id); item = init_item(id, name); if (!item) { printf("Error adding new data\n"); return; } if (!btree_add(item)) printf("Btree Error: Failed to add item\n"); return; }