Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. char* get_char_code(huffman_tree* ht, char c){
  2.     if(!ht->rght && !ht->lft){
  3.         if(ht->node->symbols[0] == c){
  4.             char* null = (char*)malloc(sizeof(char));
  5.             *null = '\0';
  6.             return null;
  7.         }
  8.         return NULL;
  9.     }
  10.     char* code = get_char_code(ht->rght, c);
  11.     char* new_code = NULL;
  12.     if(!code){
  13.         code = get_char_code(ht->lft, c);
  14.             if(code){
  15.                 new_code = (char*)malloc(2*sizeof(char)+strlen(code)*sizeof(char));
  16.                 sprintf(new_code, "0%s", code);
  17.             }
  18.     }else{
  19.         int tam = 0;
  20.         if(code) {
  21.             tam = strlen(code);
  22.         }
  23.         new_code = (char*)malloc(2*sizeof(char)+tam*sizeof(char));
  24.         sprintf(new_code, "1%s", code);
  25.     }
  26.     free(code);
  27.     return new_code;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement