psp大蛇无双2增值版:这段C代码为什么执行的时候到循环就进行不下去了

来源:百度文库 编辑:神马品牌网 时间:2024/05/08 16:42:40
#include <stdio.h>
#include <stdlib.h>
#include "type.h"
#include "sub_fun.h"
extern int total;
student* creat(int n,student *head)//¿ª±ÙеĽáµã
{
student *p1,*p2;
int sum,i;
char out;
sum=total;
if(n==0)
{
printf("¼Èë½áÊø\n");
return(head);
}
else
{
p1=p2=(student *)malloc(LEN1);
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄѧºÅ£º",total+1);
gets(p1->num);out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÐÕÃû£º",total+1);
gets(p1->name);out=getchar();out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÐÔ±ð£º",total+1);
scanf("%c",&p1->sex);out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÄêÁ䣺",total+1);
scanf("%d",&p1->age);
for(i=0;i<7;i++)
{
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄµÚ%dÃųɼ¨:",total+1,i+1);continue;
scanf("%f",&p1->score[i][0]);
}
for(;total<=sum+n-1;total++)
{
if(total==0)
{
head=p1;
continue;
}
else
p2->next=p1;
p2=p1;
p1=(student *)malloc(LEN1);
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄѧºÅ£º",total+1);
gets(p1->num);out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÐÕÃû£º",total+1);
gets(p1->name);out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÐÔ±ð£º",total+1);
scanf("%c",&p1->sex);out=getchar();
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄÄêÁ䣺",total+1);
scanf("%d",&p1->age);
for(i=0;i<7;i++)
{
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄµÚ%dÃųɼ¨:",total+1,i+1);
scanf("%f",&p1->score[i][0]);out=getchar();
}
}
p2->next=NULL;
return(head);
}
}

你的下面这段程序中的continue;用的不对。
for(i=0;i<7;i++)
{
printf("ÇëÊäÈëµÚ%d¸öѧÉúµÄµÚ%dÃųɼ¨:",total+1,i+1);continue;
scanf("%f",&p1->score[i][0]);
}
continue;语句的作用是跳过本次循环,你这样用的话continue;后面的scanf("%f",&p1->score[i][0]); 语句每次都会被跳过,不执行。还有你下一个for循环最后的continue;语句是多余的。
好好看看continue;的用法就知道了。

for(;total<=sum+n-1;total++)吗?是不是total没有初始化

不好说,可能和你的sub_fun.h有关