当前位置: 代码迷 >> C语言 >> [求助]我已经请教好多人了(创一个表然后输出)
  详细解决方案

[求助]我已经请教好多人了(创一个表然后输出)

热度:122   发布时间:2006-04-05 12:39:00.0
[求助]我已经请教好多人了(创一个表然后输出)

# 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  

----------------解决方案--------------------------------------------------------
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);


}


----------------解决方案--------------------------------------------------------

谢谢了啊我太大意了呵


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