fwfw
This commit is contained in:
parent
d0f10aa71d
commit
71064e4d39
@ -30,8 +30,10 @@ struct tree* read_tree(){
|
||||
if(!r) {
|
||||
return NULL;
|
||||
}
|
||||
r[strcspn(r, "\n")] = '\0';
|
||||
assert(r);
|
||||
buffer[strcspn(r, "\n")] = '\0';
|
||||
if(buffer[0] == '\0'){
|
||||
return NULL;
|
||||
}
|
||||
struct tree* node = calloc(1,sizeof(struct tree));
|
||||
memcpy(node->value,buffer,SIZE);
|
||||
if(buffer[0] == '*'){
|
||||
@ -42,9 +44,6 @@ struct tree* read_tree(){
|
||||
}
|
||||
node->left = read_tree();
|
||||
node->right = read_tree();
|
||||
// Ak je nacitany riadok listovy uzol ,tak netreba robit nic
|
||||
// inak rekurzivne nacitanie laveho syna
|
||||
// a rekurzivne nacitanie praveho syna
|
||||
return node;
|
||||
}
|
||||
void print_tree(struct tree* tree,int offset){
|
||||
@ -78,8 +77,9 @@ int main(void){
|
||||
char line[SIZE];
|
||||
|
||||
|
||||
while( fgets(line, sizeof(line), stdin)){
|
||||
if(strcmp(line, "\n") == 0){
|
||||
while( fgets(line, sizeof(line), stdin)){
|
||||
line[strcspn(line, "\n")] = '\0';
|
||||
if(line[0] == '\0'){
|
||||
whitespace = true;
|
||||
break;
|
||||
}
|
||||
@ -87,6 +87,7 @@ int main(void){
|
||||
}
|
||||
int numOfLeaves = count_leaves(tree);
|
||||
char answer[SIZE];
|
||||
bool exs = false;
|
||||
printf("Expert z bufetu to vie.\n");
|
||||
if(!tree || !whitespace){
|
||||
printf("Chybna databaza\n");
|
||||
@ -97,12 +98,12 @@ int main(void){
|
||||
printf("Odpovedajte 'a' pre prvu moznost alebo 'n' pre druhu moznost.");
|
||||
while(tree){
|
||||
printf("\n%s", tree->value);
|
||||
if( fgets(answer, sizeof(answer), stdin)){
|
||||
fgets(answer, sizeof(answer), stdin);
|
||||
answer[strcspn(answer, "\n")] = '\0';
|
||||
if(answer[0] == '\0'){
|
||||
printf("\nKoniec vstupu\n");
|
||||
return 0;
|
||||
|
||||
}
|
||||
answer[strcspn(answer, "\n")] = '\0';
|
||||
|
||||
if(strcmp(answer, "n") == 0){
|
||||
tree = tree->right;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user