This commit is contained in:
Maksym Kovalchuk 2026-04-16 19:54:18 +00:00
parent 4576db8ed9
commit b488da5751

View File

@ -14,12 +14,16 @@ typedef struct Tree {
// читання дерева (preorder)
Tree* readTree() {
char line[SIZE];
int error = 0;
if (fgets(line, SIZE, stdin) == NULL) return NULL;
line[strcspn(line, "\r\n")] = 0;
if (line[0] == '\0') return NULL;
if (line[0] == '\0') {
error = 1;
return NULL;
}
Tree *node = (Tree*)malloc(sizeof(Tree));
node->yes = NULL;
@ -35,6 +39,10 @@ Tree* readTree() {
node->yes = readTree();
node->no = readTree();
if (!node->yes || !node->no) {
error = 1;
}
}
return node;
@ -103,7 +111,7 @@ int main() {
Tree *root = readTree();
if (!root) {
if (!root || error) {
printf("Chybna databaza\n");
return 0;
}