here i trying to send the address of my node root which begins with a null value but i send it to the create function to allocate memory for it.it seems to allocate memory for just the node inside create and not for root.how can i allocate memory for root?not using root=create() where the function just returns address of the created node .i want to just pass a variable and allocate memory to it in different function.
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
};
struct node *root=NULL;
void create(struct node *node)
{
int num;
printf("enter the data");
scanf("%d",&num);
node=(struct node*)malloc(sizeof(struct node));
node->data=num;
printf("%d",node->data);
}
int main()
{
create(root);
if(root==NULL)
printf("null");
printf("%d",root->data);
return 0;
}