コード例 #1
0
ファイル: pa05.c プロジェクト: twidell/ty
int main (int argc , char ** argv )
{
  FILE * fptr_in = NULL;
  FILE * fptr_out = NULL;
  HuffNode * tree;
  char length;

  if(argc != 3)
    {
      printf("Not enough arguments read!\n");
      return EXIT_FAILURE;
    }

  length = strlen(argv[1]);

  fptr_in = fopen(argv[1], "r");
  fptr_out = fopen(argv[2], "w");

  if(fptr_in == NULL)
    {
      printf("File Error 1, stopping program!\n");
      return EXIT_FAILURE;
    }

if(fptr_out == NULL)
    {
      printf("File Error 2, stopping program!\n");
      return EXIT_FAILURE;
    }

  /*if(argv[1][length - 1] == 'h')
    {
      tree = read_head(fptr_in);
      Huff_postOrderPrint(head);
      }*/

  if(argv[1][length - 1] == 'h')
    {
      tree = create_chartree(fptr_in);
      Huff_postOrderPrint(tree, fptr_out);
      destroy_tree(tree);
    }
  else
    {
      tree = create_bittree(fptr_in);
      Huff_postOrderPrint(tree, fptr_out);
      destroy_tree(tree);
    }

  fclose(fptr_in);
  fclose(fptr_out);

  return EXIT_SUCCESS;

}
コード例 #2
0
ファイル: pa05.c プロジェクト: cebaker/ECE264Solution
int main(int argc, char** argv){
  
    FILE* fptr;
    int len = 0;
    char bit_char  ;
    HuffNode* head;
    
    
    if(!CheckArgCount(argc)){
       return EXIT_FAILURE;
    }
    if((fptr = OpenFile(argv[1], "rb")) == NULL){
        return EXIT_FAILURE;
    }
    
    len = strlen(argv[1]);
    bit_char = argv[1][len - 1];
    

    head = headerfileread(fptr,bit_char);
    
    Huff_postOrderPrint(head);
    CloseFile(fptr);
    
    DestroySnode(head);
    
    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: pa09.c プロジェクト: kumarv123/kumarthegreat
int main(int argc, char ** argv)
{
    
    //Check arguments
    if(argc != 3)
    {
	printf("incomplete arguments");
	return EXIT_FAILURE;
    }
    
    //initializing input file
    FILE * fptr = NULL;
    fptr = fopen(argv[1], "r");
    if (fptr == NULL)
    {
	printf("File error!\n");
	return EXIT_FAILURE;
    }
    
    int flag;
    HuffNode *tree = NULL;
    flag = checkBitCh(fptr);
    
    //Reading file and creating huffman tree
    if(flag == 0) //input file is char based
    {
	tree = Huff_CharRead(argv[1]);
    }
    
    else//input file is bit-based
    {
	tree = Huff_BitRead(argv[1]);
    }
    
    fclose(fptr);
    
    //writing the output
    fptr = fopen(argv[2], "w");
    if (fptr == NULL)
    {
	printf("File error!\n");
	return EXIT_FAILURE;
    }
    
    //This function prints the output on the output file
    Huff_postOrderPrint(tree,fptr);
    
    //This destroys the allocated memory
    Huff_destroyTree(tree);
    
    
    fclose(fptr);
    return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: utility.c プロジェクト: apoorvsgaur/creation-rings
void Huff_postOrderPrint(FILE *output_file, HuffNode *tree)
{
    if (tree == NULL) 
    {
       return;
    }

    fprintf(output_file, "Left\n");
    
    Huff_postOrderPrint(output_file, tree->left);
    fprintf(output_file, "Back\n");

    fprintf(output_file, "Right\n");
    Huff_postOrderPrint(output_file, tree->right);
    fprintf(output_file, "Back\n");
 
    if (tree->left == NULL && tree->right == NULL) 
    {
      fprintf(output_file, "Leaf: %c\n", tree->value);
    }
   return;
}
コード例 #5
0
/* DO NOT MODIFY THIS FUNCTION!!! */
void Huff_postOrderPrint(HuffNode *tree, FILE* fh)
{
    // Base case: empty subtree
    if (tree == NULL) {
		return;
    }

    // Recursive case: post-order traversal

    // Visit left
    fprintf(fh, "Left\n");
    Huff_postOrderPrint(tree->left, fh);
	fprintf(fh, "Back\n");
    // Visit right
    fprintf(fh, "Right\n");
    Huff_postOrderPrint(tree->right, fh);
	fprintf(fh, "Back\n");
    // Visit node itself (only if leaf)
    if (tree->left == NULL && tree->right == NULL) {
		fprintf(fh, "Leaf: %c\n", tree->value);
    }
    

}
コード例 #6
0
int main(int argc, char ** argv)
{
  if(argc < 2)//check if the input file name has been given or not
  {
    printf("Input filename is missing.\n");//if not, print the error message to the user
    return EXIT_FAILURE;//return the EXIT_FAILURE constant
  } 
  
  HuffNode * huff_tree = readInput(argv[1]);//call the readInput function to get the Huffman tree based on the input command in the input file
  if(huff_tree == NULL)//if the huff_tree pointer is NULL, it means the input file cannot be opened correctly.
  {
    printf("Input file cannot be opened, or it's not correct.\n");//print the error message to the user
    return EXIT_FAILURE;
  }
  
  Huff_postOrderPrint(huff_tree);//print the huffman tree
  destroyTree(huff_tree);//deallocate the memory for the huffman tree

  return EXIT_SUCCESS;
}
コード例 #7
0
ファイル: pa09.c プロジェクト: aggarw13/ECE264solutions
int main(int argc, char ** argv)
{
  if(argc != 3)
    {
      printf("ERROR! There should be three input arguments, the object file, the input file and the output file");
      return EXIT_FAILURE;
    }

  FILE * ftpr;
  ftpr = fopen(argv[1],"r");
  if(ftpr == NULL)
    {
      printf("\n Error! The input file could not be opened");
      return EXIT_FAILURE;
    }
  fclose(ftpr);
  HuffNode * Huffmannroot = NULL;
  int filetype =  readHeader(argv[1]);
  if(filetype == 0)
    {
      Huffmannroot = create_Huffmanntree(argv[1]);
    }
  else
    {
      Huffmannroot = create_HufftreeBit(argv[1]);
    }
  FILE * ftpr2 = fopen(argv[2],"w");
  if(ftpr2 == NULL)
    {
      printf("Error! The output filename argument could not be opened.");
      return EXIT_FAILURE;
    }
  Huff_postOrderPrint(Huffmannroot, ftpr2);
  tree_destroy(Huffmannroot);
  fclose(ftpr2);
  return EXIT_SUCCESS;
}