c - What does the warning - expected ‘struct node **’ but argument is of type ‘struct node **’ mean? -
my code tree creation array:
#include<stdio.h> #include<malloc.h> typedef struct { struct node* left; struct node* right; int val; }node; void create_tree(node** root,int val) { if(*root == null ) { *root = (node*)malloc(sizeof(node)); (*root)->val = val; (*root)->left = null; (*root)->right = null; return; } if((*root)->val <= val ) create_tree(&((*root)->left),val); else create_tree(&((*root)->right),val); return ; } int main() { node *root = (node*)malloc(sizeof(node)); root->val = 10; root->left = null; root->right = null; int val[] = { 11,16,6,20,19,8,14,4,0,1,15,18,3,13,9,21,5,17,2,7,12}; int i; for(i=0;i<22;i++) create_tree(&root,val[i]); return 0; } warning getting:
tree.c:10:6: note: expected ‘struct node **’ argument of type ‘struct node **’ void create_tree(node** root,int val) ^ i not able understand warning say? both expected , actual of type struct node **. bug?
after edit (that's why ask [mcve]), clear problem is.
inside struct, reference struct node. not define type, define alias node struct has no name itself.
note in c struct node resides in different namespace "normal" names variables or typedefed aliases.
so have add tag:
typedef struct node { struct node* left; struct node* right; int val; } node; that way have struct node type name node.
Comments
Post a Comment