Initializacia

This commit is contained in:
Kozar 2024-11-12 15:48:07 +00:00
parent 724940804f
commit 55853490b2

View File

@ -13,47 +13,29 @@ struct tree {
struct tree* read_tree() {
char buffer[SIZE];
while (fgets(buffer, SIZE, stdin)) {
buffer[strcspn(buffer, "\n")] = 0;
if (buffer[0] == '\0') {
continue;
}
struct tree* node = calloc(1, sizeof(struct tree));
strncpy(node->value, buffer, SIZE - 1);
return node;
memset(buffer, 0, SIZE);
char* r = fgets(buffer, SIZE, stdin);
if (!r || buffer[0] == '\n') {
return NULL;
}
return NULL;
buffer[strcspn(buffer, "\n")] = 0;
struct tree* node = calloc(1, sizeof(struct tree));
strncpy(node->value, buffer, SIZE - 1);
return node;
}
struct tree* load_tree() {
struct tree* node = read_tree();
if (!node) {
return NULL;
}
if (node->value[0] != '*') {
if (node->value[0] != '*') {
node->left = load_tree();
node->right = load_tree();
if (!node->left || !node->right) {
destroy_tree(node);
return NULL;
}
}
return node;
}
void run_tree(struct tree* tree) {
if (!tree) {
return;
@ -104,8 +86,7 @@ void count_items(struct tree* tree, int* count) {
int main() {
struct tree* root = load_tree();
printf("Expert z bufetu to vie.\n");
if (!root) {
if (!root) {
printf("Chybna databaza\n");
return 0;
}
@ -116,8 +97,7 @@ int main() {
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
run_tree(root);
destroy_tree(root);
return 0;
}