diff --git a/du6/program.c b/du6/program.c index 72760bd..8f08c43 100644 --- a/du6/program.c +++ b/du6/program.c @@ -10,6 +10,13 @@ typedef struct tree { struct tree *right; } Tree; +void strip_newline(char *s) { + int len = strlen(s); + if (len > 0 && s[len-1] == '\n') { + s[len-1] = '\0'; + } +} + // rekurzivne nacitanie stromu v preorder Tree* read_tree() { @@ -60,18 +67,24 @@ int run_system(Tree *node) { return 1; } - // list -> koniec + char c[10]; + printf("%s\n", node->value); + if (fgets(c, sizeof(c), stdin) == NULL) { + printf("Koniec vstupu\n"); + return 0; + } + strip_newline(c); + if (!node->left && !node->right) { printf("Koniec vstupu\n"); return 0; } - int c; - if (c == 'a') { + if (strcmp(c,'a') == 0) { if (node->left != NULL){ return run_system(node->left); } - } else if (c == 'n') { + } else if (strcmp(c, 'n') == 0) { if (node->right != NULL){ return run_system(node->right); }