在C中,有可能在sprintf函数中使用递归吗?出于某种原因,我得到的,当我做一个分割故障:C:sprintf和递归
inline char *TreeNode_toString(const TreeNode *node)
{
char *out;
if(TreeNode_isExternal(node)) // If the node has no children...
{
sprintf(out, "%s:%.2f", node->name, node->distance);
}
else // The node is strictly binary, so it will have two non-null children
{
char *l = TreeNode_toString(node->l); // l = left child
char *r = TreeNode_toString(node->r); // r = right child
sprintf(out, "(%s,%s):%.2f", l, r, node->distance);
}
return out;
}
你的意思是分配没有初始化 - out的说明值并不重要只是一些内存空间 – Mark 2010-05-11 18:43:37