东方航空国际航班餐食:C语言的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 16:27:33
struct student
{ int num;
char name[20];
char sex;
float score1,score2;
struct student *next;
};

struct student *head,*p1,*p2;

struct student* creat()
{ p1=(struct student*)malloc(sizeof(struct student));
head=p1;
printf("please input:num,sex,score1,score2,name\n");
do
{ p2=(struct student*)malloc(sizeof(struct student));
p1->next=p2;
p1=p2;
scanf("%d,%c,%f,%f,%s",&p1->num,&p1->sex,&p1->score1,&p1->score2,&p1->name);
}
while(p1->num!=0);

p1->next=null;
return head;
}

我想问的是为什么score定义为float型就会出错:
scanf:floating point formats not linked
abnormal program termination

另外还有个问题就是name 读字符的时候会吧后面的数据读上
除了放在最后 或是分开读还有什么办法吗??
希望高手指点一下
编译是没问题的,问题是运行的时候出的 如果score定义为int型就很正常,大家帮忙看看吧!!!谢谢了
加上下面是完整的,运行看看就知道了.

void print(struct student* head)
{
p1=head->next;
printf(" num name sex score1 score2 \n");
while(p1->num!=null)
{
printf("%7d%10s%5c%8.1f%8.1f\n",p1->num,p1->name,p1->sex,p1->score1,p1->score2);

p1=p1->next;
}

}
main()
{
printf("\n");
head=creat();
print(head);
getch();
return 0;
}

是格式化输入函数scanf的问题,在格式化输入数据时,无法指定数据精度。
所以,要么采用整型数据,要么采用字符数组。

我感觉你的问题是出在格式化输入和输出上。把格式化去了就不会有问题的哈。

我以前也遇到过这样的问题,也许是格式化输入函数scanf本身的原因吧。

编译和运行都没问题!
null要大写

我编译没有出问题哈~~

我也没有发现问题