Initializacia

This commit is contained in:
Kozar 2024-11-10 16:12:30 +00:00
parent bdb10349f2
commit f256260aca

View File

@ -21,10 +21,6 @@ struct tree* read_tree() {
}
buffer[strcspn(buffer, "\n")] = 0;
if (buffer[0] == '*' && buffer[1] == ' ') {
error_flag = 1; // Invalid format if there's a space after '*'
}
struct tree* node = calloc(1, sizeof(struct tree));
strncpy(node->value, buffer, SIZE - 1);
return node;
@ -35,7 +31,7 @@ struct tree* load_tree() {
if (!node) {
return NULL;
}
if (error_flag || node->value[0] != '*') {
if (node->value[0] != '*') {
node->left = load_tree();
node->right = load_tree();
}
@ -55,11 +51,8 @@ void run_tree(struct tree* tree) {
printf("%s\n", tree->value);
char response;
if (scanf(" %c", &response) != 1) {
printf("Koniec vstupu\n");
return;
} else if (response != 'a' && response != 'n') {
printf("Nerozumiem\n");
if (scanf(" %c", &response) != 1 || (response != 'a' && response != 'n')) {
error_flag = 1;
return;
}
@ -94,9 +87,8 @@ void count_items(struct tree* tree, int* count) {
int main() {
struct tree* root = load_tree();
printf("Expert z bufetu to vie.\n");
if (!root || error_flag) {
if (!root) {
printf("Chybna databaza\n");
destroy_tree(root);
return 0;
}
@ -107,6 +99,10 @@ int main() {
run_tree(root);
if (error_flag) {
printf("Chybna databaza\n");
}
destroy_tree(root);
return 0;
}