我的代码在这里给出了编译时错误 - "取消引用指向不完整类型的指针"在函数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;
}
答案 0 :(得分: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
。