This commit is contained in:
Bohdan Kapliuk 2024-11-11 14:32:47 +02:00
parent ae9d9a9a08
commit 0b7175626f

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define SIZE 100
struct tree {
@ -20,7 +21,7 @@ struct tree* read_tree(int* counter){
assert(r);
struct tree* tree = calloc(1, sizeof(struct tree));
tree->value = malloc(strlen(buffer) + 1);
strcpy(tree->value,r);
strcpy(tree->value, buffer);
assert(tree->value);
if (buffer[0] == '*') {
(*counter)++;
@ -40,17 +41,15 @@ void destroy_tree(struct tree* tree) {
}
void print_tree(struct tree* tree, int offset) {
char buffer[SIZE];
memset(buffer, 0, SIZE);
if (tree == NULL) return;
for (int i = 0; i < offset && tree->value[0] != '*'; i++) {
printf(" ");
}
printf("%s", tree->value);
if (tree->value[0] == '*') {
printf("Koniec\n");
exit(0);
printf("Koniec vstupu\n");
return;
}
getchar();
char r = getchar();
if (r == 'a') {
print_tree(tree->left, offset + 3);