request for member in something not a structure or union, but its a struct

this code is a binary search tree I'm doing for my 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; } for (i = 0; i<level; i++) { printf(" "); } printf("%s %d\n", node->name, level); preorder(node->left, level + 1); preorder(node->right, level + 1); }

This is my Full code. Well I deleted not necessary bits of codes, but thats all I 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 this is the Node type I'm using.

at the insert_tree, inserting one node is OK.

but when i use strncmp, it get errors. "Request for member in something not a structure or union"

isn't root a Node Struct?

I dont get why i get errors..

can somebody help me out?

I've wasted about 4 hours only to solve that problem..

sorry for my poor english due to nationality

-------------Problems Reply------------

See operator precedence, where -> is having precedence over *. You should use (*root)->name as argument to your strncmp() call.

Category:c# Views:0 Time:2018-05-14

Related post

Copyright (C), All Rights Reserved.

processed in 3.840 (s). 12 q(s)