0
有人可以帮我访问一个联合中的指针,我不断得到一个[错误]无效类型参数' - >'(有'结构节点')。下面是我的数据结构的片段在里面:C编程:访问一个联盟中的指针
typedef enum{LEAF,INODE}indicator;
typedef struct twoThree{
indicator indic;
union{
struct L{
int key;
}leaf;
struct node{
int key1,key2;
struct twoThree *LC,*MC,*RC;
}iNode;
}U;
}*TTT;
void insertElem(TTT *T, int elem)
{
TTT *temp;
if(*T==NULL){
*T=initTree();
(*T)->indic = LEAF;
(*T)->U.leaf.key = elem;
}else if((*T)->indic == LEAF){
if(elem < (*T)->U.leaf.key){
(*temp)=initTree();
(*temp)->indic = INODE;
(*temp)->U.iNode.key1 = elem;
**(*temp)->U.iNode->LC = *T; /*This is my problem"->LC" part*/**
}
}
}
TTT initTree()
{
TTT T;
T=(TTT)malloc(sizeof(struct twoThree));
if(T!=NULL){
printf("Initialization of tree was successful.\n");
}else{
printf("Failed initialization of tree.\n");
}
return T;
}
如果任何人都可以对我如何在联盟内访问我的指针指出,这将是巨大的。多谢你们。
您有多个错误。对于初学者来说,当您解除引用时,“temp”指向何处? –
'typedef struct twoThree {...} * TTT' - 在大多数情况下'typedef'指针是个不错的主意。 –
至于你的问题,'U.iNode'不是一个指向结构的指针,它是一个结构*对象*,因此你不应该使用箭头运算符' - >'来访问它的成员。 –