Question

My code here gives me compile time error - "dereferencing pointer to a incomplete type" in the function InsertList. Iam unable to figure out why. What am I doing wrong?

#include<stdio.h>
#include<stdlib.h>

struct ListNode;
struct ListNode{
int data;
struct ListNode* next;
};

void main(int argc,char* argv[]){

int p;
FILE *ptr;
FILE *out;

//ptr=fopen("C:\Users\dheeraj\Desktop\input.txt","r");
out=fopen("output.txt","w");

struct Listnode* head=0;

while(fscanf(ptr,"%d",&p) != EOF){
InsertList(head,p);
}
close(ptr);
}

void InsertList(struct Listnode** headref,int data)
{

struct Listnode* newNode= malloc(sizeof(struct ListNode));
if(newNode == 0)
    printf("Memory error\n");

newNode->data=data;
newNode->next = (*headref);
(*headref )=newNode;

}
Was it helpful?

Solution

void InsertList(struct Listnode** headref,int data)

should be:

void InsertList(struct ListNode** headref,int data)

Also:

struct Listnode* newNode= malloc(sizeof(struct ListNode));

should be:

struct ListNode* newNode= malloc(sizeof(struct ListNode));

Do a global search for Listnode and replace with ListNode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top