linux段错误 15

头文件#include<stdio.h>#include<stdlib.h>#include<string.h>#include<malloc.h>#defineLENs... 头文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#define LEN sizeof(struct Student)
#define NULl 0
int I;
struct Student
{ int num;
char name[20];
char class[30];
float chinesescore;
float mathscore;
float sum;
struct Student *next;
};

void read1(char *ch,struct Student *p);

void sum1(char *ch,struct Student *p);

void sort1(char *ch,struct Student *p);

main函数
#include "head.h"
int main()
{
struct Student *p;
printf("共有学生多少?");
scanf("%d",&I);

read1("chengji",p);
sum1("chengji",p);
sort1("chengji",p);
return 1;
}

read1.c
#include "head.h"
void read1(char *ch,struct Student *p)
{ FILE *fp;
fp=fopen(ch,"a+");
p=(struct Student *)malloc(LEN);
struct Student *p2;
struct Student *head;
head=NULL;
int t=0;
p2=p;
for(t=0;t <I;t++)
{
if(t==0)head=p;
else p2->next=p;
p2=p;
p=(struct Student *)malloc(LEN);
printf("请输入第%d个学生的学号,姓名,班级,语文成绩,数学成绩",t+1);
scanf("%d%s%s%f%f",&p->num,p->name,p->class,&p->chinesescore,&p->mathscore);
printf("学号:%d姓名:%s班级:%s语文成绩:%.1f数学成绩:%.1f总分:%.1f\n",p->num,p->name,p->class,p->chinesescore,p->mathscore,p->sum);
}
p2->next=NULL;
p=head;
fwrite(p,sizeof(struct Student),I,fp);

int m;
for(m=0;m <I;m++)
{ p->sum=0;p=p->next;}
p=head;
for(m=0;m <I;m++)
{printf("学号:%d姓名:%s班级:%s语文成绩:%.1f数学成绩:%.1f总分:%.1f\n",p->num,p->name,p->class,p->chinesescore,p->mathscore,p->sum);p=p->next;}
fclose(fp);

}

运行到read1.c的第一个for循环结束就报错----------段错误
请高手指点!!!
展开
 我来答
百度网友371b25b
2008-12-01 · TA获得超过121个赞
知道小有建树答主
回答量:303
采纳率:0%
帮助的人:210万
展开全部
你的FOR循环没意义嘛
int t=0;
p2=p;
for(t=0;t <I;t++)
定义了T=0,还让FOR去判断,循环只做一次,那干脆就直接把下面拉出来做呢
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式