tags:

views:

91

answers:

2

Hi

I am new to linux c programming and i have a simple program just for learning and when i compile it it gives me error "dereferencing pointer to incomplete type" here is my code

struct Node
{
    struct Node* left;
    struct Node* middle;
    struct Node* right;
    int nodeData;
    int nodeLevel;
    char isVisted;
};
struct ListNode
{
    struct Node* data;
    struct ListNode* next;
};

struct List
{
    struct NodeList* head;
    struct NodeList* tail;
    int count;
};

typedef struct ListNode ListNode;
typedef struct Node Node;
typedef struct List List;

ListNode* InitListNode(Node* data)
{
    ListNode* listNode=(ListNode*)calloc(1,sizeof(ListNode));
    listNode->data=data;
    listNode->next=NULL;
    return listNode;
}

List* InitList()
{
    List* list=(List*)calloc(1,sizeof(List));
    list->count=0;
    list->head=list->tail=NULL;
}

void EnQue(Node* data,List* que)
{
    if(que->count==0)
    {
        que->tail=que->head=InitListNode(data);
        que->count++;
    }
    else
    {
        que->tail->next=InitListNode(data); //here error is problem comes 
        que->tail=que->tail->next;//here error is problem comes
        que->count++;
    }
}

please help..

+6  A: 

head and tail in struct List are of type NodeList. Should be ListNode?

berne
thanx a lot solution works.. but one thing why compiler don't give any error stating that NodeList does not exist as i havn't created this struct.
Ahsan Iqbal
NodeList does exist - but only as an incomplete type. In your case this translates to "a struct whose members have not been specified yet". And that's exactly what the compiler told you.
RWS
thanx for your response
Ahsan Iqbal
+2  A: 

Looks like there is a typo in your definition of List. I believe it should be ListNode, which is defined, instead of NodeList which is not defined. Try the following

struct List
{
    struct ListNode* head;
    struct ListNode* tail;
    int count;
};
JaredPar
thanx for your response bro
Ahsan Iqbal