Prog03a - /-/ Name: George Corser / Program: CSC 375...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
//------------------------------------------------------------------------ // Name: George Corser // Program: CSC 375 Program 3 (Prog03.cpp) // Due Date: 03/18/2009 // Compiler: Bloodshed Dev-C++ 4.9.9.2 // // Comments: HUFFMAN TREE ENCODING // This program creates an encoded output file from an input file. // The basic steps are as follows. // 1. Read the input file and count the frequency that each // character (letter or punctuation mark or space) is used. // 2. Sort the characters by frequency. // 3. Create a Huffman tree based on the frequencies. // 4. Create a code assignment table based on the Huffman tree. // 5. Re-read the input file and write a new, encoded output file. // // Variables (VARIABLE DICTIONARY): // argc - number of command line arguments // argv - character array of command line arguments // pFile - pointer to the input file // currenttext - text of the current line of the input file // currentchar - current character // // Variables for linked list for storing character frequencies: // node - structure for the linked list of currency denominations // inchar - input character // frequency - the number of times a character was used // next - pointer to the next node in the linked list // root - pointer to the first (header) node in the linked list // conductor - pointer of the current node in the linked list // (used for traversing the list) // //------------------------------------------------------------------------ #define MAXLINE 256 // max length of input line #define MAXCHARS 128 // max number of possible characters #define MAXHUFF 20 // max length of huffman code #define LEFT '0' #define RIGHT '1' #define NONE ' ' #define FALSE 0 #define TRUE 1 #define INTERNALNODE '~' #include <iostream> // for cout calls #include <fstream> // for ifstream call #include <string> // for c_str() function #include "huffman.h" // huffman tree class using namespace std; // for string declaration int cur_hufflength = 0; // length of huffman code (while traversing) char cur_huffcode[MAXHUFF]; int thishuff = 0; // position of code added to array below char hufftable[MAXCHARS][MAXHUFF];// huffman code (while traversing) // note: cur_huffcode[0] == inchar, and // cur_huffcode[>0] is the actual code // 0 = left, 1 = right, ' ' = nothing void assignhuff(node *subtree, char LR); // assign huffman code from tree
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
main(int argc, char *argv[]) { // -------------------- Check for input errors ----------------------- FILE * iFile; // file containing input text FILE * oFile; // file containing output codes if (argc < 3) { cout << "Not enough arguments - Usage: prog03 infile.txt outfile.txt \n"; exit(1); } if (argc > 3) { cout << "Too many arguments - Usage: prog03 infile.txt outfile.txt \n"; exit(1); } iFile = fopen (argv[1],"r"); // open input file if (iFile==NULL) { cout << "Could not open file: " << argv[1] << "\n"; exit (1); } fclose(iFile);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/19/2010 for the course CSC 375 taught by Professor Turner during the Spring '09 term at University of Michigan-Dearborn.

Page1 / 6

Prog03a - /-/ Name: George Corser / Program: CSC 375...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online