| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 476 人关注过本帖
标题:[求助]我已经请教好多人了(创一个表然后输出)
只看楼主 加入收藏
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
 问题点数:0 回复次数:2 
[求助]我已经请教好多人了(创一个表然后输出)

# include<stdio.h>
# include<malloc.h>
# define NULL 0
# define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};


struct student *creat(void) ********创一个表输入的值是1101,65 1105,98 1124,95 0,0
{ int i; 但结果是1101,98 1105,95 1124,0
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *) malloc (LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
i=0;
while(p1->num!=0)
{ i=i+1;
if(i==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p2->score);


}
p2->next=NULL;
return(head);


}

void print(struct student *head) \\\\输出一个表\\
{struct student *p;
p=head;
if(head!=NULL)
do
{printf("%ld,%f",p ->num,p ->score);
p=p->next;
} while(p!=NULL) ;
getch();
}

void main()
{struct student *creat();
void print(struct student *);
struct student *head;printf("\nInput the A records:\n");
head=creat();
print(head);
getch(); \\\\\\\最后说明问题是可以输出结果但不准确是
}

搜索更多相关主题的帖子: include 
2006-04-05 12:39
gail
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-3-29
收藏
得分:0 
struct student *creat(void) ********创一个表输入的值是1101,65 1105,98 1124,95 0,0
{ int i; 但结果是1101,98 1105,95 1124,0
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *) malloc (LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
i=0;
while(p1->num!=0)
{ i=i+1;
if(i==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);//应该是1吧


}
p2->next=NULL;
return(head);


}


2006-04-05 12:58
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 

谢谢了啊我太大意了呵


明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-04-05 16:25
快速回复:[求助]我已经请教好多人了(创一个表然后输出)
数据加载中...
 
   



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

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