为什么不能我访问指针“细胞”等的阵列?我已经分配了相应的内存,为什么不在这里像一个数组?它就像一个数组,用于基本数据类型的指针。错误:无效类型参数“ - >”(具有“结构节点”)
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 10
struct node
{
int e;
struct node *next;
};
typedef struct node *List;
typedef struct node *Position;
struct Hashtable
{
int Tablesize;
List Cells;
};
typedef struct Hashtable *HashT;
HashT Initialize(int SIZE,HashT H)
{
int i;
H=(HashT)malloc(sizeof(struct Hashtable));
if(H!=NULL)
{
H->Tablesize=SIZE;
printf("\n\t%d",H->Tablesize);
H->Cells=(List)malloc(sizeof(struct node)* H->Tablesize);
它应该不像从这里的数组行事?
if(H->Cells!=NULL)
{
for(i=0;i<H->Tablesize;i++)
以下行是抛出该错误的那些
{ H->Cells[i]->next=NULL;
H->Cells[i]->e=i;
printf("\n %d",H->Cells[i]->e);
}
}
}
else printf("\nError!Out of Space");
}
int main()
{
HashT H;
H=Initialize(10,H);
return 0;
}
我得到的错误是在标题中错误:invalid type argument of '->' (have 'struct node').
首先,缩进代码。 – Kunal
'H-> Cells - > [i] e'绝对不是正确的语法。 – godel9
然后注意'H-> Cells - > [i] e = i;'不是C语法。 –