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;
}
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.