Created
December 1, 2016 23:03
-
-
Save harveyslash/f60f39df5c16bbe3119e7dcf4f881329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE *input = fopen(argv[1],"rb"); | |
FILE *output; | |
unsigned short header =0; | |
fread(&header,1,sizeof(unsigned short),input); | |
if(header == magicNumber){ | |
rewind(input); | |
if(argc==3 && argv[2][0]!='-'){ | |
output=fopen(argv[3],"w"); | |
handleDecode(input,output); | |
fclose(output); | |
fclose(input); | |
} | |
else{ | |
handleDecode(input,stdout); | |
fclose(input); | |
} | |
} | |
else{ | |
/*printf("IN ELSE\n");*/ | |
fclose(input); | |
input = fopen(argv[1],"r"); | |
readFromFile(input); | |
fclose(input); | |
input = fopen(argv[1],"r"); | |
Heap mainHeap =populateHeap(); | |
TreeNode * root = (TreeNode*)removeTopHeap(mainHeap); | |
int arr[256]; | |
getCodes(root,arr,0); | |
fclose(input); | |
input = fopen(argv[1],"r"); | |
unsigned int *bitArr =generateBitArrayEncore(input); | |
FILE *output = fopen(argv[2],"wb"); | |
unsigned short magic = 0x80F0; | |
fwrite(&magic,1,sizeof(unsigned short),output); | |
writeTreeToFile(root,output,0); | |
fwrite(&totalBitsUsed, 1, sizeof(unsigned int), output); | |
//printf("FINAL PRINT 0,%u\n",bitArr[0]); | |
//printf("FINAL PRINT 1,%u\n",bitArr[1]); | |
int sizeOfArray = (totalBitsUsed/(sizeof(unsigned int)*8)) + (totalBitsUsed%(sizeof(unsigned int)*8) == 0 ? 0:1); | |
/*printf("SIZE OF ARRAY IS %d\n",sizeOfArray);*/ | |
fwrite(bitArr, sizeOfArray, sizeof(unsigned int), output); | |
fclose(output); | |
fclose(input); | |
destroyHeap(mainHeap); | |
freeTree(root); | |
free(bitArr); | |
/*free(root);*/ | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment