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