| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:译码出问题了,该怎么解决啊?
只看楼主 加入收藏
wxtx
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-5-15
收藏
 问题点数:0 回复次数:1 
译码出问题了,该怎么解决啊?


void HuffmanEncode( FILE *fp, BITFILE *bf)
{
unsigned long filelength;
int i;
BuildCounts( fp);
fseek( fp, 0, SEEK_END);
filelength = ftell( fp);
BitsOutput( bf, filelength, 4*8);
for( i=0; i<256; i++) BitsOutput( bf, counts[i], 4*8);
BuildTree( );
BuildCode( );
fseek( fp, 0, SEEK_SET);
while( EOF!=(i=fgetc(fp)))
{
BitsOutput( bf, hCode[i].code, hCode[i].codelength);
}
}

void HuffmanDecode( BITFILE *bf, FILE *fp)
{
unsigned long filelength;
int i;
int rootNode;
int node;

filelength = ftell( fp);
if( -1 == filelength) filelength = 0;
// reading the counts
for( i=0; i<256; i++) counts[i] = BitsInput( bf, 4*8);
rootNode = BuildTree( );
while( 0<filelength)
{
node = rootNode;
do{
if( 0 == BitInput( bf)) node = hTree[node].lchild;
else node = hTree[node].rchild;
}while( 255<node);
fputc( node, fp);
filelength --;
}
}
void CMy111Dlg::OnCode()
{
if(m_Path == "")
{
AfxMessageBox("请选择路径");
return;
}

//译码,编码
char *ch = m_Filename.GetBuffer(0);
FILE *fp;
BITFILE *bf;
CString str = "";
CString str1 = "";

this->m_Style.GetWindowText(str1);
this->m_Code.GetWindowText(str);
if( str == "编码")
{ // do encoding
fp = fopen( m_Filename, "rb");
bf = OpenBitFileOutput( "result.txt");
if( NULL!=fp && NULL!=bf)
{
if( str1 == "huffman")

fclose( fp);
CloseBitFileOutput( bf);
}
}
else
if( str == "译码")
{ // do decoding
bf = OpenBitFileInput( "_result.txt");
fp = fopen( m_Filename, "r");
if( NULL!=fp && NULL!=bf)
{
if( str1 == "huffman")
HuffmanDecode(bf,fp);

fclose( fp);
CloseBitFileInput( bf);
}
}
对一文本文件编码,能够成功,但对编码后的结果译码,出不了结果,老是生成空文件,大家帮忙帮我看看!!!

搜索更多相关主题的帖子: 译码 filelength void BitsOutput 
2007-06-01 23:22
wxtx
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-5-15
收藏
得分:0 
2007-06-02 12:32
快速回复:译码出问题了,该怎么解决啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019796 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved