Prog03 - Name George Corser Program CSC 375 Program...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //------------------------------------------------------------------------// 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 of this program 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.////------------------------------------------------------------------------#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 classusing namespace std; // for string declaration// GLOBAL VARIABLESint cur_hufflength = 0; // length of huffman code (while traversing)char cur_huffcode[MAXHUFF];int thishuff = 0; // position of code added to array belowchar hufftable[MAXCHARS][MAXHUFF];// huffman code (while traversing)// note: cur_huffcode[0] == inchar, and // cur_huffcode[>0] is the actual code// 0 = left, 1 = right, ' ' = nothingvoid assignhuff(node *subtree, char LR); // assign huffman code from treemain(int argc, char *argv) {// -------------------- Check for input errors -----------------------FILE * iFile; // file containing input textFILE * oFile; // file containing output codesif (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 fileif (iFile==NULL) {cout << "Could not open file: " << argv[1] << "\n"; exit (1);}fclose(iFile);// -------------------------- Declare and initialize variables string currenttext; // current line of input text char currentchar; // current character of input text // -------------------------- Initialize linked list node *root; // header/first node in linked listnode *conductor; // pointer for traversing the linked listroot = new node; // root points to a new node struct...
View Full 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

Prog03 - Name George Corser Program CSC 375 Program...

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