/*
@function build_tree
@desc builds the symbol tree given the list of symbols and code.h
NOTE: alters the global variable root that has already been allocated in main
*/ void build_tree(FILE* fp) { char symbol; char strcode[MAX_LEN]; int items_read; int i, len; struct tnode *curr =NULL;
while(!feof(fp)){
items_read =fscanf(fp,"%c %s\n",&symbol, strcode); if(items_read != 2) break;
curr = root;
len =strlen(strcode); for(i = 0; i < len; i++){ /*TODO: create the tree as you go */
/*
function decode
*/ void decode(FILE* fin,FILE* fout) { char c; struct tnode *curr = root; while((c =getc(fin))!=EOF){ /*TODO:
traverse the tree
print the symbols only if you encounter a leaf node
*/
if('1'== c)
curr = curr->right; elseif('0'== c)
curr = curr->left;