This commit is contained in:
Bohdan Kapliuk 2024-11-11 19:05:13 +02:00
parent 8d15749214
commit 00f8a74436

View File

@ -15,11 +15,18 @@ struct tree* read_tree(int* counter) {
memset(buffer, 0, SIZE); memset(buffer, 0, SIZE);
char* r = fgets(buffer, SIZE, stdin); char* r = fgets(buffer, SIZE, stdin);
if (buffer[0] == '\n') { if (buffer[0] == '\n') {
printf("Chybna databaza\n"); return NULL;
return 0;
} }
struct tree* tree = calloc(1, sizeof(struct tree)); struct tree* tree = calloc(1, sizeof(struct tree));
if(tree == NULL){
printf("Chybna databaza\n");
exit(0);
}
tree->value = malloc(strlen(buffer) + 1); tree->value = malloc(strlen(buffer) + 1);
if(tree->value == NULL){
printf("Chybna databaza\n");
exit(0);
}
strcpy(tree->value, buffer); strcpy(tree->value, buffer);
if (buffer[0] == '*') { if (buffer[0] == '*') {
(*counter)++; (*counter)++;
@ -63,6 +70,7 @@ int main() {
int counter = 0; int counter = 0;
struct tree* root = read_tree(&counter); struct tree* root = read_tree(&counter);
printf("Expert z bufetu to vie.\n"); printf("Expert z bufetu to vie.\n");
printf("Pozna %d druhov ovocia a zeleniny.\n", counter); printf("Pozna %d druhov ovocia a zeleniny.\n", counter);
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n"); printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.\n");
print_tree(root); print_tree(root);