www.pudn.com > arithmetic_demo.zip > decode.cpp


// decode.cpp : Defines the entry point for the console application. 
// 
 
#include "stdafx.h" 
 
#include "model.h" 
 
 
class CDecode 
: public CArithmeticModel 
{ 
public: 
	int GetByte() 
	{ 
        return getc(stdin);			 
	} 
	void main() 
	{ 
		start_model();				/* Set up other modules.    */ 
		start_inputing_bits(); 
		start_decoding(); 
		for (;;) {					/* Loop through characters. */ 
			int ch; int symbol; 
			symbol = decode_symbol(cum_freq);	/* Decode next symbol.      */ 
			if (symbol==EOF_symbol) break;		/* Exit loop if EOF symbol. */ 
			ch = index_to_char[symbol];		/* Translate to a character.*/ 
			putc(ch,stdout);			/* Write that character.    */ 
			update_model(symbol);			/* Update the model.        */ 
		} 
	} 
}; 
 
int main(int /*argc*/, char* /*argv[]*/) 
{ 
	_setmode( _fileno( stdin ), _O_BINARY ); 
	_setmode( _fileno( stdout ), _O_BINARY ); 
 
	CDecode model; 
	model.main(); 
 
	return 0; 
}