• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Memory alloocation in C

Bluga

Banned
Is my memeory allocation correct? Thanks.

=============================================

typedef struct TreeNode {

int num_of_keys;
int *keys;
struct TreeNode **children;

} TREENODE;


struct TreeNode* Insert(struct TreeNode *root, int key)
{
int i, k;

if (root == NULL)
{
/* init node: */
root = (TreeNode *) malloc(sizeof(TreeNode));
root->num_of_keys = 0;
keys = NULL;
children = NULL;

}
}
 
You *should* test that malloc was successful.

Also, I don't see that code compiling. There are about 4 small syntax errors.
 
Back
Top