DEV C++里建立一个工程,有好几个文件,编译就是不通过,会出“dereferencing pointer to incomplete type”错误!单个就可以,代码是没问题的!
main.c代码:
#include “Stdio.h”
#include “stdlib.h”
#define LEN sizeof(struct student)
struct student
{
long num;
char name[10];
float scores[2];
struct student *next;
}stu;
struct student * creat_list(void);
void print(struct student *head);
struct student *del(struct student * head);
int main(void)
{
/* 此处添加你自己的代码 */
struct student *pa=NULL,*pb=NULL;
pa=creat_list();
print(pa);
pa=del(pa);
print(pa);
getch();
}
creat.c代码:
extern struct student stu;
struct student * creat_list(void)
{
struct student * head=NULL,*ppre=NULL,*pafter=NULL;
ppre=pafter=(struct student *)malloc(sizeof(struct student));
printf(“请输入学号:”);
scanf(“%ld”,&ppre->num);
if(ppre->num!=0)
{
printf(“请输入姓名:”);
scanf(“%s”,ppre->name);
printf(“请输入数学成绩:”);
scanf(“%f”,&ppre->scores[0]);
printf(“请输入语文成绩:”);
scanf(“%f”,&ppre->scores[1]);
head=ppre;
while(pafter->num!=0)
{
pafter=(struct student *)malloc(sizeof(struct student));
printf(“请输入学号:”);
scanf(“%ld”,&pafter->num);
if(pafter->num==0)
ppre->next=NULL;
else
{
printf(“请输入姓名:”);
scanf(“%s”,pafter->name);
printf(“请输入数学成绩:”);
scanf(“%f”,&pafter->scores[0]);
printf(“请输入语文成绩:”);
scanf(“%f”,&pafter->scores[1]);
ppre->next=pafter;
ppre=pafter;
}
}
}
free(pafter);
free(ppre);
return (head);
}
print.c代码:
extern struct student stu;
void print(struct student *head)
{
struct student *q=NULL;
printf(“\nnow print:\n”);
q=head;
if(head!=NULL)
do
{
printf(“%ld %s %5.1f %5.1f\n”,q->num,q->name,q->scores[0],q->scores[1]);
q=q->next;
}while(q!=NULL);
else printf(“None\n”);
}
请高手指教!!
>> 本文固定链接: http://www.vcgood.com/archives/2157
没人吗?