int
main(int argc, char* argv[]) {
  int c,maxCount;
  
  if (argc != 4) {
    fprintf(stderr,"Syntax:%s input_file output_file codetable_file\n", 
	argv[0]);
    exit(1);
  }
  inFile = fopen(argv[1], "r");
  outFile = fopen(argv[2], "w+");
  codeTableFile = fopen(argv[3], "w+");
  
  memset(counter, 0, sizeof(count_t)*256 );
  for(;;) {
    c = fgetc(inFile);
    if (c < 0) break;
    bigcounter[c]++;  
  }  

  if (fseek(inFile, 0, SEEK_SET) ) {
    perror("Couldn't seek for re-read\n");
    exit(1);
  }

  for(c=0, maxCount=0; c<256; c++) {
    if (maxCount < bigcounter[c]) maxCount = bigcounter[c];
    if (!bigcounter[c]) bigcounter[c]++;
  }

  printf("maxCount = %d\n", maxCount);
  for(c=0; c<256; c++) {
    counter[c].weight = (128 * bigcounter[c]) /(maxCount +1); 
    counter[c].used = 0;
  } 

  fwrite(counter, 1, 256, codeTableFile); //write code table file to disk
  fclose(codeTableFile);

  buildTree();
  puts("Tree succesfully completed");

  buildCode(minUnusedParent-1, 0,0);  
  puts("Built Code table");
  compress();
  puts("Finished compression");

  fclose(outFile);
  fclose(inFile);
  return 0;
}   

