输入错误,请帮忙改正
用char anum1[10]数组的形式输入后score这个值为何会变成随机值啊,高手帮个忙,谢谢
#include<stdio.h>
#include<stdlib.h>
//#include<string.h>
struct student{
//long int anum;
char anum[10];
float score;
struct student * next;
};
struct student * creatstu(void);
void printstu(struct student * head);
int main()
{
struct student * head;
head=creatstu();
printstu(head);
return 0;
}
struct student * creatstu(void)
{
struct student * head ,* p1,* p2;
char anum1[10];
head=p1=p2=NULL;
p2=p1=(struct student *)malloc(sizeof(struct student));
/*scanf("%s",anum1);*/
/*strcpy(p1->anum,anum1);*/
scanf("%s,%f",p1->anum1,&p1->score);/*这里改成用STRCPY拷贝或anum改成long输入就问题*/
printf("%s\n%f\n",p1->anum1,p1->score);
while(p1->score){
if(head==NULL)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(sizeof(struct student));
scanf("%s,%f",p1->anum1,&p1->score);
printf("%s\n%f\n",p1->anum1,p1->score);
}
p2->next=NULL;
return head;
}
void printstu(struct student * head)
{
struct student *p=head;
while(p)
{
printf("%10ld%10d\n",p->anum,p->score);
p=p->next;
}
return;
}