Fixing the empty test
This commit is contained in:
parent
5aa8f2e938
commit
4a00c12f43
@ -3,7 +3,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#define SIZE 100
|
#define SIZE 1000
|
||||||
|
|
||||||
|
|
||||||
struct tree{
|
struct tree{
|
||||||
@ -27,6 +27,9 @@ struct tree* read_tree(){
|
|||||||
char buffer[SIZE];
|
char buffer[SIZE];
|
||||||
memset(buffer,0,SIZE);
|
memset(buffer,0,SIZE);
|
||||||
char* r = fgets(buffer,SIZE,stdin);
|
char* r = fgets(buffer,SIZE,stdin);
|
||||||
|
if(!r){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
r[strcspn(r, "\n")] = '\0';
|
r[strcspn(r, "\n")] = '\0';
|
||||||
assert(r);
|
assert(r);
|
||||||
struct tree* node = calloc(1,sizeof(struct tree));
|
struct tree* node = calloc(1,sizeof(struct tree));
|
||||||
@ -39,9 +42,6 @@ struct tree* read_tree(){
|
|||||||
}
|
}
|
||||||
node->left = read_tree();
|
node->left = read_tree();
|
||||||
node->right = 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;
|
return node;
|
||||||
}
|
}
|
||||||
void print_tree(struct tree* tree,int offset){
|
void print_tree(struct tree* tree,int offset){
|
||||||
@ -73,11 +73,6 @@ int main(void){
|
|||||||
|
|
||||||
struct tree* tree = read_tree();
|
struct tree* tree = read_tree();
|
||||||
char line[SIZE];
|
char line[SIZE];
|
||||||
|
|
||||||
if(!tree){
|
|
||||||
printf("Bazu sa nedalo nacitat'.\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
while( fgets(line, sizeof(line), stdin)){
|
while( fgets(line, sizeof(line), stdin)){
|
||||||
line[strcspn(line, "\n")] = '\0';
|
line[strcspn(line, "\n")] = '\0';
|
||||||
if(line[0] == '\0'){
|
if(line[0] == '\0'){
|
||||||
@ -86,14 +81,14 @@ int main(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!whitespace){
|
if(!whitespace && tree != NULL){
|
||||||
printf("No whitespace after database\n");
|
printf("No whitespace after database\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int numOfLeaves = count_leaves(tree);
|
int numOfLeaves = count_leaves(tree);
|
||||||
char answer[SIZE];
|
char answer[SIZE];
|
||||||
printf("Expert z bufetu to vie.\n");
|
printf("Expert z bufetu to vie.\n");
|
||||||
if(!tree){
|
if(tree == NULL){
|
||||||
printf("Chybna databaza\n");
|
printf("Chybna databaza\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user