/* File: main8d.c * * Demonstrate binary search tree * This version reads data from a file. * * * */ #include #include #include "bst2.h" int main() { tnode *tree = NULL ; char filename[256], nom[256] ; FILE *ifile ; int r, freq ; printf("\n\n### Testing bst_insert() ###\n") ; printf("Filename (max 255 char): ") ; scanf("%256s", filename) ; ifile = fopen(filename, "r") ; if (ifile ==NULL) { fprintf(stderr, "Could not open file for reading: %s\n", filename) ; exit(1) ; } while(1) { r = fscanf(ifile, "%256s %d", nom, &freq) ; if (r < 2) break ; printf("Adding %s, %d\n", nom, freq) ; tree = bst_insert(tree, nom, freq) ; } fclose(ifile) ; printf("-------------------------------------------------------------------\n") ; bst_walk_depth(tree,0) ; printf("-------------------------------------------------------------------\n") ; bst_destroy(tree) ; return 0 ; }