Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* get_char_code(huffman_tree* ht, char c){
- if(!ht->rght && !ht->lft){
- if(ht->node->symbols[0] == c){
- char* null = (char*)malloc(sizeof(char));
- *null = '\0';
- return null;
- }
- return NULL;
- }
- char* code = get_char_code(ht->rght, c);
- char* new_code = NULL;
- if(!code){
- code = get_char_code(ht->lft, c);
- if(code){
- new_code = (char*)malloc(2*sizeof(char)+strlen(code)*sizeof(char));
- sprintf(new_code, "0%s", code);
- }
- }else{
- int tam = 0;
- if(code) {
- tam = strlen(code);
- }
- new_code = (char*)malloc(2*sizeof(char)+tam*sizeof(char));
- sprintf(new_code, "1%s", code);
- }
- free(code);
- return new_code;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement