关于链表的一个小问题
pa1es 2003-09-29 04:46:36 在写出建表,打印表函数
运行出现 scanf:floating point formats not linked
Abnormal program termination.
请问是何原因。
程序如下:
#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct a)
struct a
{ float xishu;
int zhishu;
struct a *next;
};
int n;
/*creat table*/
struct a *creat(void)
{struct a *head;
struct a *p1,*p2;
n=0;
p1=p2=(struct a *) malloc (LEN);
scanf("%f,%d",&p1->xishu,&p1->zhishu);
head=NULL;
while(p1->xishu!=0)
{ n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct a *) malloc (LEN);
scanf("%f,%d",&p1->xishu,&p1->zhishu);
}
p2->next=NULL;
return(head);
} /* creat table*/
/* print table*/
void print(struct a *head)
{struct a *p;
printf("\nOutput what you input.\n");
p=head;
if(head!=NULL)
do
{printf("%fx^%d",p->xishu,p->zhishu);
if (p->next!=NULL)
printf("+");
else printf("\n");
p=p->next;
}
while (p!=NULL);
}
main()
{ struct a *head_x;
head_x=creat();
print(head_x);
}