diaz
diaz

Reputation: 53

Enter a value into a struct pointer

I make code like this:

typedef struct t_node{
    struct node *left;
    struct node *right;
    int info;
}node;

typedef struct t_node *Tree;

then I use this procedure to create the tree , it's just a simple procedure

void createTree(Tree *T){
    (*T)->info = NULL;
}

But I get error about assignment makes integer from pointer without a cast and I can't understand it. Can someone help me ?

Upvotes: 2

Views: 68

Answers (2)

NadavL
NadavL

Reputation: 400

When you use (*Tree), you de-reference the pointer, but then you de-reference it again, by using (Tree)-> which is the equivalent of ((*Tree)).

In short, either use

(*T).info = NULL;

or

T->info = NULL;

In your case though, I see that this is warranted since Tree is a typedef of struct node* ,so what you're doing is correct.

NULL is 0 cast to a pointer, and that is giving you compilation errors since info is a int and not a pointer. change 'NULL' to '0'.

Upvotes: 2

haccks
haccks

Reputation: 106092

(*T)->info is an int as info is declared int in structure. NULL is a pointer.

Upvotes: 2

Related Questions