帮忙调试一个函数
大虾,帮忙调试一下:
struct student * creat_list_a(void)
{
struct student * head=NULL,*ppre=NULL,*pafter=NULL;
ppre=pafter=(struct student *)malloc(sizeof(struct student));
printf(“please input num:”);
scanf(“%ld”,&ppre->num);
if(ppre->num!=-1)
{
printf(“please input name:”);
scanf(“%s”,ppre->name);
printf(“please input math score:”);
scanf(“%f”,&ppre->scores[0]);
printf(“please input chinese score:”);
scanf(“%f”,&ppre->scores[1]);
head=ppre;
for(;pafter->num==-1;)
{
pafter=(struct student *)malloc(sizeof(struct student));
printf(“\nplease input num:”);
scanf(“%ld”,&pafter->num);
if(pafter->num==-1)
ppre->next=NULL;
else
{
printf(“\nplease input name:”);
scanf(“%s”,pafter->name);
printf(“\nplease input math score:”);
scanf(“%f”,&pafter->scores);
printf(“\nplease input chinese score:”);
scanf(“%f”,&pafter->scores);
ppre->next=pafter;
}
}
return (head);
}
问题:输完name之后,一闪而过!
struct student * creat_list_a(void)
{
struct student * head=NULL,*ppre=NULL,*pafter=NULL;
ppre=pafter=(struct student *)malloc(sizeof(struct student));
printf(“please input num:”);
scanf(“%ld”,&ppre->num);
if(ppre->num!=-1)
{
printf(“please input name:”);
scanf(“%s”,ppre->name);
printf(“please input math score:”);
scanf(“%f”,&ppre->scores[0]);
printf(“please input chinese score:”);
scanf(“%f”,&ppre->scores[1]);
head=ppre;
for(;pafter->num==-1;)
{
pafter=(struct student *)malloc(sizeof(struct student));
printf(“\nplease input num:”);
scanf(“%ld”,&pafter->num);
if(pafter->num==-1)
ppre->next=NULL;
else
{
printf(“\nplease input name:”);
scanf(“%s”,pafter->name);
printf(“\nplease input math score:”);
scanf(“%f”,&pafter->scores);
printf(“\nplease input chinese score:”);
scanf(“%f”,&pafter->scores);
ppre->next=pafter;
}
}
return (head);
}
问题:输完name之后,一闪而过!
>> 本文固定链接: http://www.vcgood.com/archives/2144
开始的scanf没有&,后面的*pafter MS没有用啊(和head没有联系)。。。。你的程序没看懂,呵呵,请见谅
那里没有&啊?
辛苦了,同志们,我知道原因了,原来是WIN-TC的问题!!
WIN-TC和TC2。0都有一个问题 。就是小数转换问题,象scanf(“%f”,&ppre->scores[0]);这句就会有”scanf:float point formats not linked”的错误!
解决方法见:http://hi.baidu.com/eocodes/blog/item/9b25972308e69845ac34de4b.html