| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 365 人关注过本帖
标题:[求助]单链表问题
只看楼主 加入收藏
linsongbin
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-6-9
收藏
 问题点数:0 回复次数:2 
[求助]单链表问题

#include<stdio.h>
#include<malloc.h>
#include <conio.h>
/**************************************************************/
struct student
{
int num;
struct student *next;
};
/************************创建链表****************************/
struct student *create()
{
struct student *head;
head=(struct student *)malloc(sizeof(struct student));
head->next=NULL;
return head;
}
/************************录入数据******************************/
void Input(struct student *h)
{
struct student *p,*last=h;
while(1)
{
p=(struct student *)malloc(sizeof(struct student));

printf("请输入学生学号:");scanf("%d",&p->num);

p->next=NULL;
last->next=p;last=p;

int ch;
printf("要继续输入下一个吗(y/n)");ch=getch();
if(ch=='y'||ch=='Y')
{
}
else
{
free(p);
break;
}
}
}
/************************显示链表******************************/
void Disp(struct student *h)
{
printf("\n\n");

struct student *p=h;

while(p->next!=NULL)
{
p=p->next;
printf("学号为:%d\n",&p->num);
}
}
/***************************************************************/
void main()
{
struct student *h;
h=create();
Input(h);
Disp(h);
}
/***************************************************************/



为什么老是出错??

[此贴子已经被作者于2007-7-22 20:40:04编辑过]

搜索更多相关主题的帖子: 单链 
2007-07-22 20:36
anlogo
Rank: 2
等 级:论坛游民
威 望:1
帖 子:293
专家分:20
注 册:2007-7-20
收藏
得分:0 
这里错了啊:
void Disp(struct student *h)
{
printf("\n\n");

struct student *p=h;

while(p->next!=NULL)
{
p=p->next;
printf("学号为:%d\n",p->num);
}
}

注意:printf("学号为:%d\n",p->num);
2007-07-22 20:57
linsongbin
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-6-9
收藏
得分:0 
以下是引用anlogo在2007-7-22 20:57:08的发言:
这里错了啊:
void Disp(struct student *h)
{
printf("\n\n");

struct student *p=h;

while(p->next!=NULL)
{
p=p->next;
printf("学号为:%d\n",p->num);
}
}

注意:printf("学号为:%d\n",p->num);

啊~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~这都没看见。。。。。。。。。。。。

[此贴子已经被作者于2007-7-22 21:37:51编辑过]

2007-07-22 21:34
快速回复:[求助]单链表问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015154 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved