结构体里面能否有float 谢谢
下面程序运行时被中断 说是浮点指针错误 把struct node 里面的 score 从float改
为long 程序便可正常运行 请问为什么?
#define NULL 0
#include <stdio.h>
#include <stdlib.h>
struct node
{long num;
float score;
struct node *next;
};
struct node *creat (void)
{struct node *head;
struct node *p1,*p2;
head=NULL;
p1=p2=(struct node *)malloc(sizeof(struct node));
clrscr();
printf ("input -1 to stop \n");
printf ("input the num :");
scanf ("%ld",&p1->num);
printf ("\ninput the score : ");
scanf ("%f",&p1->score);
while (p1->num!=-1)
{if (head==NULL) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct node *)malloc(sizeof(struct node));
clrscr();
printf ("input -1 to stop \n");
printf ("input the num :");
scanf ("%ld",&p1->num);
printf ("\ninput the score : ");
scanf ("%f",&p1->score);
}
return (head);
}
main()
{creat();};