pa09.c 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "pa09.h"
  5. int main(int argc, char * argv[])
  6. {
  7. char length;
  8. HuffNode * tree = NULL;
  9. if(argc != 3)
  10. {
  11. printf("Not enough input arguments.\n");
  12. return EXIT_FAILURE;
  13. }
  14. FILE * input_file_ptr = fopen(argv[1], "r");
  15. FILE * output_file_ptr = fopen(argv[2], "w");
  16. if(input_file_ptr == NULL)
  17. {
  18. printf("The input file does not exist.");
  19. return EXIT_FAILURE;
  20. }
  21. if(output_file_ptr == NULL)
  22. {
  23. printf("The output file does not exist.");
  24. return EXIT_FAILURE;
  25. }
  26. length = strlen(argv[1]);
  27. if(argv[1][length - 1] == 'h')
  28. {
  29. tree = create_character_tree(input_file_ptr);
  30. Huff_postOrderPrint(tree, output_file_ptr);
  31. }
  32. if(argv[1][length - 1] == 't')
  33. {
  34. tree = load_header(input_file_ptr);
  35. }
  36. tree_destroy(tree);
  37. fclose(input_file_ptr);
  38. fclose(output_file_ptr);
  39. return EXIT_SUCCESS;
  40. }