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

#include<stdio.h>
#define LEN sizeof(struct student)
struct student
{int data;
struct student *next;
};


struct student *creat(struct student *head)
{struct student *p1,*newp;
head=(struct student *)malloc(LEN);
p1=(struct student *)malloc(LEN);
scanf("%d",&p1->data);
head=p1;
p1->next=NULL;
newp=(struct student*)malloc(LEN) ;
while(1)
{printf("please input the data");
scanf("%d",&newp->data);
if(newp->data==0)
break;
newp->next=NULL;
p1->next=newp;
p1=newp;

newp=(struct student*)malloc(LEN) ;
}
return head;
}
void Print(struct student *head)
{struct student *p;
p=head;
while(p->next!=NULL)
printf("%d\n",p->data);
p=p->next; }
main()
{struct student *head;
creat(head);
Print(head);
}
虽然通过了编译可是输出结果不对,一直输出很多数字,难道是跳不出while()循环

忘不吝赐教!

搜索更多相关主题的帖子: 链表 student struct 动态 LEN 
2006-08-08 16:49
快速回复:求助,动态链表的问题
数据加载中...
 
   



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

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