www.pudn.com > arithmetic_demo.zip > encode.cpp
// encode.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "model.h" class CEncode : public CArithmeticModel{ public: void PutByte(int byte) { putc(byte, stdout); /* now full. */ } void main() { start_model(); /* Set up other modules. */ start_outputing_bits(); start_encoding(); for (;;) { /* Loop through characters. */ int ch; int symbol; ch = getc(stdin); /* Read the next character. */ if (ch==EOF) break; /* Exit loop on end-of-file.*/ symbol = char_to_index[ch]; /* Translate to an index. */ encode_symbol(symbol,cum_freq); /* Encode that symbol. */ update_model(symbol); /* Update the model. */ } encode_symbol(EOF_symbol,cum_freq); /* Encode the EOF symbol. */ done_encoding(); /* Send the last few bits. */ done_outputing_bits(); } }; int main(int /*argc*/, char* /*argv[]*/) { _setmode( _fileno( stdin ), _O_BINARY ); _setmode( _fileno( stdout ), _O_BINARY ); CEncode model; model.main(); return 0; }