指针问题请指导
#include <stdio.h>#include<string.h>
struct student
{
int iNum;
char cName[16];
float fChineseScore;
float fMathScore;
float fEnglishScore;
};
typedef struct student STUDENT;
void five()
{
void InputTranscript2(STUDENT *Myclass,int num);
STUDENT FindTop(STUDENT *MyClass,int num);
void print(STUDENT *high);
void print(STUDENT classmate);
STUDENT *FindByName(STUDENT *Myclass,int num,char *pName);
STUDENT sTranscript2[3],*p,*p1,high,result;
int n=3;
char xm[16];
p=sTranscript2;
InputTranscript2(p,n);
high=FindTop(p,n);
print(high);
printf("\n请输入你要查询的学生姓名:");
scanf("%s",xm);
p1=FindByName(p,n,xm);
result=*p1;
print(result);
}
void InputTranscript2(STUDENT *Myclass,int num)
{
int i;
printf("Input info of Student:N0. Name ChineseScore MathScore EnglishScore\n");
printf("注意:严格按照给定的格式输入!\n");
for(i=0;i<num;i++)
{
scanf("%d %s %f %f %f",&(Myclass+i)->iNum,&(Myclass+i)->cName,&(Myclass+i)->fChineseScore,&(Myclass+i)->fMathScore,&(Myclass+i)->fEnglishScore);
}
}
STUDENT FindTop(STUDENT *Myclass,int num)
{
int m,i;
float sum[3];
STUDENT max;
for(i=0;i<num;i++)
{
sum[i]=(Myclass+i)->fChineseScore+(Myclass+i)->fMathScore+(Myclass+i)->fEnglishScore;
}
for(i=0,m=0;i<num;i++)
{
if(sum[m]<sum[i])
{
m=i;
}
}
max=*(Myclass+m);
return max;
}
void print(STUDENT classmate)
{
printf("你所查询的学生的信息为:\n");
printf("学号:%d 姓名:%s 中文成绩:%.2f 数学成绩:%.2f 英语成绩:%.2f\n",classmate.iNum,,classmate.fChineseScore,classmate.fMathScore,classmate.fEnglishScore);
}
STUDENT *FindByName(STUDENT *Myclass,int num,char *pName)
{
int i;
for(i=0;i<num;i++)
{
if (strcmp(((Myclass+i)->cName),(pName))==0)
{
return (Myclass+i);
break;
}
else return NULL;
}
}
int main()
{
five();
return 0;
}
请问为什么用姓名查询学生的信息时程序会崩溃?该如何解决?