0

我的代码在这里给了我编译时错误-函数 InsertList 中的“取消引用指向不完整类型的指针”。我无法弄清楚为什么。我究竟做错了什么?

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

}
4

1 回答 1

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

应该:

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

还:

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

应该:

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

进行全局搜索Listnode并替换为ListNode.

于 2013-10-29T19:09:00.183 回答