Memory alloocation in C

Bluga

Banned
Nov 28, 2000
4,315
0
0
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;

}
}
 

manly

Lifer
Jan 25, 2000
13,341
4,102
136
You *should* test that malloc was successful.

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