c - request for member in something not a structure or union, but its a struct -
this code binary search tree i'm doing school assignment.
#include "binary_tree.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #define maxlen 10 node* create_tree() { return null; } void insert_tree(node** root, char* nname, char* number) { if (*root==null){ node* node = (node *)malloc(sizeof(node)); strncpy(node->name , nname, maxlen); strncpy(node->number , number, maxlen); node->left = node->right = null; *root = node; return; } if (strncmp(*root->name, nname, maxlen)) { insert_tree(&(*root)->left, nname, number); } else { insert_tree(&(*root)->right, nname, number); } } void preorder(node* node, int level){ int i; if (node==null){ //printf("null\n"); return; } (i = 0; i<level; i++) { printf(" "); } printf("%s %d\n", node->name, level); preorder(node->left, level + 1); preorder(node->right, level + 1); }
this full code. deleted not necessary bits of codes, thats need right know..
typedef struct t_node { char name[maxlen + 1]; char number[maxlen + 1]; struct t_node *left; struct t_node *right; } node;
and node type i'm using.
at insert_tree, inserting 1 node ok.
but when use strncmp, errors. "request member in not structure or union"
isn't root node struct?
i dont why errors..
can me out?
i've wasted 4 hours solve problem..
sorry poor english due nationality
see operator precedence, ->
having precedence on *
. should use (*root)->name
argument strncmp()
call.
Comments
Post a Comment