小反刍疫苗免疫时间:这段c代码的循环部分哪儿错了

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 17:29:59
请看看为什么程序为什么执行到循环部分就出错了
#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);
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);
}
}
头文件里的代码
#define LEN1 sizeof(struct student)
struct student
{
char num[11];
char name[10];
char sex;
int age;
float score[7][1];
struct student *next;
};
student* creat(int n,student *head);
student* input(struct student *head);
for循环是第一个for循环出问题了
即使那个scanf("%f",&p1->score[i][0]);的这句

p1->score[i][0] 要先初始化 = 0