当前位置: 代码迷 >> C语言 >> [求助]关于链表的问题,谢谢(跪求多时无人了)
  详细解决方案

[求助]关于链表的问题,谢谢(跪求多时无人了)

热度:120   发布时间:2007-09-18 22:18:48.0
[求助]关于链表的问题,谢谢(跪求多时无人了)

我写了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

用dev C++编译后显示:

(list.c中)



(main.c中)
请问这是什么原因啊,求解,谢谢!



[此贴子已经被作者于2007-9-18 23:04:19编辑过]

搜索更多相关的解决方案: 链表  

----------------解决方案--------------------------------------------------------
谁帮下忙啊?我看了半天,没搞懂
----------------解决方案--------------------------------------------------------
求助啊~~~~~~~~~~等了好久了
----------------解决方案--------------------------------------------------------
destroy函数没有声明??
还有,貌似你建立了错误的工程,并不是Console



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

[url=http://bbs.bc-cn.net/viewthread.php?tid=163571]请大家不要用TC来学习C语言,点击此处查看原因[/url]
[url=http://bbs.bc-cn.net/viewthread.php?tid=162918]C++编写的Windows界面游戏[/url]
[url=http://yzfy.org/]C/C++算法习题(OnlineJudge):[/url] http://yzfy.org/
----------------解决方案--------------------------------------------------------

哦,谢谢了


----------------解决方案--------------------------------------------------------
  相关解决方案