error: invalid type argument of '->' (have 'struct node')

Posted by Roshan S.A on Stack Overflow See other posts from Stack Overflow or by Roshan S.A
Published on 2013-10-26T14:11:50Z Indexed on 2013/10/27 9:54 UTC
Read the original article Hit count: 264

Why cant i access the pointer "Cells" like an array ? i have allocated the appropriate memory why wont it act like an array here? it works like an array for a pointer of basic data types.

#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);

should it not act like an array from here on?

        if(H->Cells!=NULL)
        {
            for(i=0;i<H->Tablesize;i++)

the following lines are the ones that throw the error

            { 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;
}

The error I get is as in the title-error: invalid type argument of '->' (have 'struct node').

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers