| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 526 人关注过本帖
标题:[求助]链表综合操作老是调试错误?
只看楼主 加入收藏
浩然
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-11-20
收藏
 问题点数:0 回复次数:1 
[求助]链表综合操作老是调试错误?

谭浩强《C程序设计第二版》中11.7.8节(P286)中的链表综合操作怎么调都有错程序能运行但是结果是错误的,在此求救各位了马上就要交作业了先谢谢大家:)
运行的时候老是出现这个问题:"scanf:floating point formats not linked Abnormal program termination"
附程序如下:
#include<malloc.h>
#define null 0
#define len sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};
int n;
struct student *creat(void)
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(len);
scanf("%ld,%f",&p1->num,&p1->score);
head=null;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(len);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=null;
return(head);
}
void print(struct student *head)
{struct student *p;
printf("\nnow,these %d records are:",n);
p=head;
if(head!=null)
do
{printf("%ld%5.lf\n",p->num,p->score);
p=p->next;
}while(p!=null);
}
struct student *insert(struct student *head,struct student *stud)
{struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==null)
{head=p0;p0->next=null;}
else
{while((p0->num>p1->num)&&(p1->next!=null))
{p2=p1;
p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;}
else
{p1->next=p0;p0->next=null;}}
n=n+1;
return(head);
}
struct student *del(struct student *head,long num)
{struct student *p1,*p2;
if(head==null) {printf("\nlist null!\n");goto end;}
p1=head;
while(num!=p1->num&&p1->next!=null)
{ p2=p1;
p1=p1->next;}
if(num==p1->num)
{ if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("delete:%d\n",num);
n=n-1;
}
else printf("%ld not been found!\n",num);
end:return(head);
}
main()
{
struct student *head,*stu;
long del_num;
printf("input records:\n");
head=creat();
print(head);
printf("\ninput the delete number:");
scanf("%ld",&del_num);
while(del_num!=0)
{head=del(head,del_num);
print(head);
printf("input the delete number:");
scanf("%ld",&del_num);}
printf("\ninput the inserted record:");
stu=(struct student*)malloc(len);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num!=0)
{head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student*)malloc(len);
scanf("%ld,%f",&stu->num,&stu->score);
}
}

运行结果应该是这样的:
input records:
99101,99↓
99103,87↓

99105,77↓

0,0↓

Now,These 3 records are:
99101 99.0
99103 87.0
99105 77.0

input the deleted number:99103↓

delete:99103

Now,These 2 records are:
99101 99.0
99105 77.0

input the deleted number:99105↓

delete:99105

Now,These 1 records are :
99101 90.0

input the deleted number:0↓


input the inserted record:99104,87↓


Now,These 2 records are:
99101 99.0
99104 87.0

input the inserted record:99106,65↓


Now,These 3 records are:
99101, 99.0
99104,87.0
99106,65.0

input the inserted record:0 ↓

[此贴子已经被作者于2006-11-20 17:36:32编辑过]

搜索更多相关主题的帖子: 链表 student 谭浩强 struct 调试 
2006-11-20 09:32
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 

没有问题呀,我调试的很好,是不是你的输入有问题
只发现一个地方有问题
//in function: void print(struct student *head)
printf("%ld%5.lf\n",p->num,p->score);


2006-11-20 13:24
快速回复:[求助]链表综合操作老是调试错误?
数据加载中...
 
   



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

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