/**
 * @brief deconstructs the tree
 *
 * @param self the binary tree
 */
void binary_tree_destroy(binary_tree *self) {
  if (!(self->left == self->right) && (self->left == NULL)) {
    binary_tree_destroy(self->left);
    binary_tree_destroy(self->right);
  }
  free(self);
  self = NULL;
}
Exemplo n.º 2
0
void play(FILE* inputFile){
  if(inputFile == NULL){
    printf("IN HERE\n");
    inputFile = fopen("src/animals.tree", "w+");
    fputs("Aelephant", inputFile);
    rewind(inputFile);
  }
  binary_tree* tree = binary_tree_create_f(inputFile);
  if(inputFile != NULL){
  printf("Welcome to the Animals game!\n"); //starts the game
  printf("\n");
  printf("Shall we play a game? "); //asks to play
  char c;
  scanf(" %c", &c); //scans for either a 'y' or 'n' char
  while(c == 'y'){
    char* val;
    tree = playRound(inputFile, tree); //plays the game
    printf("\n");
    printf("Shall we play a game? "); //asks to play
    scanf(" %c", &c); //scans for either a 'y' or 'n' char
  }
  printf("Bye!\n"); //quits the game
  freopen("src/animals.tree", "w", inputFile); //makes a blank file to be written to
  binary_tree_write(tree, inputFile); //writes the new information to the file
  rewind(inputFile); //rewinds to the beginning of the file
  fclose(inputFile); //closes the file
  binary_tree_destroy(tree); //free's the malloc'ed memory
  return;
}
else{
  printf("File is null or not in the correct format\n");
}
}