我写了3个文件main.c list.c pub.h
main.c:
#include <stdio.h>
#include <malloc.h>
#include "pub.h"
int main()
{
struct student *head1,*head2;
head1 = creat();
head2 = creat();
destroy(head1);
destroy(head2);
getchar();
return 1;
}
list.c:
#include <stdio.h>
#include <malloc.h>
#include "pub.h"
struct student *creat()
{
struct student head;
struct student *p;
int num;
float scroe;
head.next = NULL;
scanf("%d,%f",&num,&scroe);
while(num != 0)
{
p = (struct student *)malloc(LEN);
if(p == NULL)
{
printf("memory is not enough!\n");
break;
}
p->num = num;
p->scroe = scroe;
p->next = head.next;
head.next = p;
scanf("%d,%f",&num,&scroe);
}
if(p == NULL)
{
destroy(head.next);
return NULL;
}
return head.next;
}
int destroy(struct student *head)
{
struct student *p = head;
struct student *pNext = NULL;
while(p != NULL)
{
pNext = p->next;
free(p);
p = pNext;
}
return 1;
}
pub.h
#ifndef _STULIST_H
#define _STULIST_H
struct student
{
int num;
float scroe;
struct student *next;
};
struct student *creat();
int destroy(struct student *head);
#define LEN sizeof(struct student)
#endif
(list.c中)
(main.c中)
请问这是什么原因啊,求解,谢谢!
[此贴子已经被作者于2007-9-18 23:04:19编辑过]