【发布时间】:2019-06-16 06:18:15
【问题描述】:
这段代码有什么问题吗?我无法用它解码霍夫曼。 fault : 分段错误(核心转储)
char *real_bin = "100101111101001100"
struct tree
{
int fre;
char c;
struct tree *left;
struct tree *right;
};
typedef struct tree tree;
void decode_huffman(tree *root, char *real_bin)
{
tree *p = root;
int m = strlen(real_bin);
for (int i = 0; i < m; i++)
{
if (real_bin[i] == '0')
{
p = p->left;
}
else
{
p = p->right;
}
if (p->c != '\0')
{
printf("%c\n", p->c);
p = root;
}
}
}
【问题讨论】:
-
是的。此代码不完整。请发帖minimal reproducible example。
-
如果您遇到段错误并且原因不明显,是时候使用调试器找出发生段错误的行了。
-
帮帮我!请...
-
如果您没有提供足够的信息,人们将无法帮助您。要么是Minimum, Complete, Verifiable Example,要么至少是一些关于问题发生位置的额外信息。只需使用调试器运行您的程序,您就会知道问题出在哪里。
-
我在回答中提供了它们。你能帮帮我吗?
标签: c decoding huffman-code