I return a error code from create_node function so that if memory not available it returns to the main and the program ends. I get an error that comparison of integer to pointer. Can you please help me to deal with it. I am a beginner. Thanks.
node *create_node(void)
{
node *newnode = (node *)malloc(sizeof(node));
if (newnode == NULL)
return 1;
newnode->right = NULL;
newnode->left = NULL;
return newnode;
}
int main(void)
{
int ret_val = 0;
node *root = create_node();
if (root == 1) {
printf("Memory not available to create a node\n");
return 0;
}
root->left = create_node();
if (root->left == 1) {
printf("Memory not available to create a node\n");
return 0;
}
root->right = create_node();
if (root->right == 1) {
printf("Memory not available to create a node\n");
return 0;
}
}