C编译错误:请求非结构或联合中的成员
我目前正在尝试创建一个字符串哈希表。然而,在我的搜索函数中,我遇到了一个错误:在非结构或联合中请求成员。。再次C编译错误:请求非结构或联合中的成员,c,list,compiler-errors,linked-list,hashtable,C,List,Compiler Errors,Linked List,Hashtable,我目前正在尝试创建一个字符串哈希表。然而,在我的搜索函数中,我遇到了一个错误:在非结构或联合中请求成员。。再次 /*search hash table*/ ListC search(hash_ref h, char* key){ ListC* tempList; int hashvalue= hashing(h, key); 46 for(tempList= h->List[hashvalue]; tempList!=NULL; temp
/*search hash table*/
ListC search(hash_ref h, char* key){
ListC* tempList;
int hashvalue= hashing(h, key);
46 for(tempList= h->List[hashvalue]; tempList!=NULL; tempList=tempList->next){
47 if(strcmp(tempList->key,key)==0){
return tempList;
}
}
return NULL;
}
/*hash function*/
int hashing(hash_ref h, char* key){
int hashvalue=0;
for(hashvalue=0;key!='\0';key++){
hashvalue= *key + (hashvalue*5) - hashvalue;
}
return hashvalue%h->size;
}
/*HashTable struct*/
typedef struct HashTable{
int size;
ListC **List;
}hash;
typedef struct Node{
long key;/*book id*/
long count;
struct Node* next;
struct Node* prev;
}NodeType;
typedef NodeType* NodeRef;
typedef struct ListCount{
NodeRef first;
NodeRef last;
NodeRef current;
long length;
}ListCount;
ListC在我的头文件中定义为
typedef struct ListCount* ListC;
在第46行和第47行,我得到一个错误,即key和next是非结构的成员。我不确定这里有什么问题
typedef struct ListCount* ListC;
所以ListC
是指针类型
ListC* tempList;
模板列表
是指向列表计数
的指针
... tempList=tempList->next ...
模板列表
未指向具有名为next
的成员的结构
我认为这说明了为什么为指针类型定义typedef
通常是个坏主意。无论如何,你必须跟踪间接性的级别;如果所有指针类型都是显式的,那么这样做通常更容易
typedef struct ListCount *ListC;
这句话可能不是你的意思
=ListC
struct ListCount*
=ListC*
struct ListCount**
struct ListCount *foo = *whatever;
foo.next;
这当然是错误的
尽量不要定义指针typedef,这样就不会明显地表明它们是指针typedef。例如,如果确实需要,您可以
typedef struct ListCount*ListCPtr
;或者只是typedef struct ListCount ListC
,这就是我认为您想要的。ListC是指向直接指向结构ListCount的指针的指针。因此,*LiatC没有下一个成员或键。检查您的typedef定义。listC的定义是什么?如何定义结构listC?您的
templast
属于指向listC的指针类型,但您尚未显示如何定义listC
。现在,您的节点
类型似乎是唯一一个定义下一个
字段的类型。呜呜,对不起!我刚刚编辑了我原来的帖子。但是ListC是在我的头文件中定义的,那么解决这个问题的更简单的方法是什么呢?问题是如果我将它更改为typedef struct ListCount ListC,并且仍然产生相同的错误。我甚至将哈希结构中的ListC**列表更改为ListC*列表,但仍然产生相同的错误
struct ListCount *foo = *whatever;
foo.next;