我写了一段程序,用VC编译,说以下有下划线的地方有错:
void HuffmanCodebuid (HuffmanTree HT,int n,int* Code)
{
int start,c,i,f;
char cd[n];
for(i=1;i<=n;++i)
{start=n-1;
for(c=i,f=HT[i].parent;f!=0;c=f,f=HT[f].parent)//反向存入内存,得到正向Huffman编码
if(HT[f].lchild==c) cd[--start]="0";//左子是0,右子是1
else cd[--start]="1";
}
printf("%s\n",cd);
Compress(cd,n,start,Code);
free(cd);//释放工作空间
}
调试信息如下:
--------------------Configuration: Huffman - Win32 Debug--------------------
Compiling...
Huffman.cpp
D:\我的文档\数据结构\Huffman\Huffman.cpp(51) : error C2057: expected constant expression
D:\我的文档\数据结构\Huffman\Huffman.cpp(51) : error C2466: cannot allocate an array of constant size 0
D:\我的文档\数据结构\Huffman\Huffman.cpp(51) : error C2133: 'cd' : unknown size
D:\我的文档\数据结构\Huffman\Huffman.cpp(55) : error C2440: '=' : cannot convert from 'char [2]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\我的文档\数据结构\Huffman\Huffman.cpp(56) : error C2440: '=' : cannot convert from 'char [2]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
执行 cl.exe 时出错.
Huffman.exe - 1 error(s), 0 warning(s)
我觉得对了阿,没错阿,为什么他说有错?请各位指教