在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