配列のようにポインター「セル」にアクセスできないのはなぜですか? 適切なメモリを割り当てましたが、ここで配列のように機能しないのはなぜですか? 基本データ型のポインターの配列のように機能します。
#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').